section31 Posted April 30, 2004 Posted April 30, 2004 ok...this is is just an example of what I need...don't ask why i would need such a thing b/c its for some script i'm writing for fun... a very simple mysql table... TABLE urls ->FIELD1 INT "id" this is set to primary and autoincrement ->FIELD2 VARCHAR "urls" what would be the most efficient way to find the next (id) integer in line to be pushed onto the database. Is there an easy way around this w/o doing a major query to the database. Trying to find the next Cardinality of that key. Remember: the ID is set to autoincrement so it would just be a query to find the max id on that table and just increment.. thanks, Dave Quote
SlitheryImp Posted May 1, 2004 Posted May 1, 2004 I'm not sure I understand your question correctly because, if you enter a value for FIELD2 and leave FIELD1 as NULL or zero, MySQL will handle the auto-increment for you when you post. If you want to handle the auto increment yourself you need something like this: result = SELECT MAX(FIELD1) FROM MySQLTable; if result = Null then MyNextRecordNumber = 1 else MyNextRecordNumber = (result + 1) This will most likely not work at all, (it is only pseudo code), but it gives you an idea of how to tackle the problem. Quote
section31 Posted May 1, 2004 Author Posted May 1, 2004 thanks...I ended up using the max funciton u stated above.... Thanks anyway. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.