Re: unique id

From: Date: Thu, 11 Jan 2001 07:44:16 +0000
Subject: Re: unique id
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-33931@lists.php.net to get a copy of this message
*WHY* not use auto_increment? Would the builtin http://php.net/uniqid function not work better? *NEVER* seed the random number generator more than once per script. Call srand() once, and only once. The return() statement will return the MySQL resource ID, which is probably not useful, but all the other variables will be forgotten so I think whatever pointer and loop position 0 you mean will be reset-- assuming all this is in a function. You are limiting yourself to 99999 - 10000 records, which is pretty small. Basically, you almost for sure are making your life difficult and should just use auto_increment. ----- Original Message ----- From: AJDIN BRANDIC <abrandic@coventry.ac.uk> Newsgroups: php.general Sent: Tuesday, January 09, 2001 11:14 AM Subject: [PHP] unique id > 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 > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#33931) next »