unique id

From: Date: Tue, 09 Jan 2001 17:16:01 +0000
Subject: unique id
Groups: php.general 
Request: Send a blank email to php-general+get-33483@lists.php.net to get a copy of this message
Hi again, I am generating a randum number but before inserting it into a table I want to make sure that onother number with the same value doesn't exist in the table. Here is what I have: srand((double)microtime()*1000000); $ran_num = rand(10000, 99999); $query01 = "SELECT thisnum FROM mytable"; $results = mysql_query($query01) or die("Failed on select mytable!"); while ($result = mysql_fetch_array($results)) { $thisnum=$result['thisnum']; if($ran_num==$thisnum) { srand((double)microtime()*1000000); $ran_num = rand(10000, 99999); reset($results) // will this reset the pointer and will the while loop start from position 0??? If not how do I force the check to start from position 0? } } I donot want to use autoincrement??? Thanks Ajdin

« previous php.general (#33483) next »