January 30th, 2000, 03:03 PM
-
Hi,
I have a table with 4 columns, one of which is an ID column. Each row has to have a unique ID, so I was thinking that I could tell PHP to find the last row in "id", and Add 1 to it, and insert this onto the next row - that way it remains unique.
But how?
Thanks,
Will
January 31st, 2000, 03:57 AM
-
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by localads:
Hi,
I have a table with 4 columns, one of which is an ID column. Each row has to have a unique ID, so I was thinking that I could tell PHP to find the last row in "id", and Add 1 to it, and insert this onto the next row - that way it remains unique.
But how?
Thanks,
Will[/quote]
Hi Will,
If you work with MySQL as database, you can assign an AUTO-INCREMENT to the primary ID column. Every new inserted value will be unique and incremented by 1.
Peter
January 31st, 2000, 06:16 AM
-
Also, doing this the way you've planned is dangerous. What happens if two visitors access the same script simultaneously?
January 31st, 2000, 09:10 AM
-
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
Also, doing this the way you've planned is dangerous. What happens if two visitors access the same script simultaneously?[/quote]
Well, to be sure: just catch the last inserted ID within the current connection (link) to the database: $lastID = mysql_insert_id().
But it should be no problem, because MySQL keeps track of the connections.
Otherwise, what use would it have in a multi-user environment?
Peter
January 31st, 2000, 10:47 AM
-
I wasn't speaking to you PAV.