#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2000
    Posts
    7
    Rep Power
    0
    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    15
    <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
  4. #3
  5. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Also, doing this the way you've planned is dangerous. What happens if two visitors access the same script simultaneously?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 1999
    Location
    Netherlands
    Posts
    77
    Rep Power
    15
    <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
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    I wasn't speaking to you PAV.

Similar Threads

  1. Adding time to time
    By bizantium in forum PHP Development
    Replies: 2
    Last Post: February 4th, 2004, 10:43 AM
  2. specific row with mysql
    By glassgorilla in forum PHP Development
    Replies: 8
    Last Post: January 28th, 2004, 10:05 AM
  3. Replies: 0
    Last Post: January 3rd, 2004, 08:33 AM
  4. error 1055 - column alias, group by, having count
    By smossbarg in forum MySQL Help
    Replies: 0
    Last Post: December 8th, 2003, 05:59 PM
  5. adding a new column in FirebirdSQL .
    By zapa in forum Firebird SQL Development
    Replies: 1
    Last Post: November 13th, 2003, 05:59 PM

IMN logo majestic logo threadwatch logo seochat tools logo