MySQL Forums
Forum List  »  PHP

Re: Generate random unique IDs
Posted by: Matt Kelley
Date: September 30, 2008 07:58PM

Why not just add a unique ID every time a row is added? To be safe, just set the unique ID first, and check the table to make sure that there are no other rows containing that same unique ID (with an 8-digit ID it shouldn't be too grand of a problem, depending on how many rows you are planning on adding with unique IDs)

to check, just use the SELECT * FROM table WHERE unique_ID = '$yourGeneratedID' statement inside a mysql_num_rows() function.

If the result is 0, that means there aren't any rows containing that ID so it's safe to use, obviously.

Options: ReplyQuote


Subject
Written By
Posted
September 17, 2008 01:58AM
September 17, 2008 10:28PM
September 24, 2008 05:08PM
January 29, 2009 08:09AM
January 29, 2009 11:58PM
Re: Generate random unique IDs
September 30, 2008 07:58PM
October 03, 2008 11:57PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.