[PHP] while loop- will this work?

2003-01-30 Thread SpyProductions Support Team


Should this work?

$f1 = rand(999,999);

while($check_sid = mysql_query(SELECT * FROM that_table WHERE this =
'$f1')){

$f1 = rand(999,999);

}


i.e. put the random number in a loop to check and make sure it is already
not in use?

Thanks,

-Mike



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] while loop- will this work?

2003-01-30 Thread Matt Schroebel

 -Original Message-
 From: SpyProductions Support Team [mailto:[EMAIL PROTECTED]] 
 Sent: Thursday, January 30, 2003 12:57 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] while loop- will this work?
 
 
 
 
 Should this work?
 
 $f1 = rand(999,999);
 
   while($check_sid = mysql_query(SELECT * FROM 
 that_table WHERE this =
 '$f1')){
 
   $f1 = rand(999,999);
 
 }
 
 
 i.e. put the random number in a loop to check and make sure 
 it is already
 not in use?

If you check the result set for a match.  $result being true will only
mean the sql executed, and not that the value was in the table.  So you
should do a mysql_fetch_row($result) and if it succeeds the row exists
in the table.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] while loop- will this work?

2003-01-30 Thread Roedel, Mark
 -Original Message-
 From: SpyProductions Support Team [mailto:[EMAIL PROTECTED]] 
 Sent: Thursday, January 30, 2003 11:57 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] while loop- will this work?
 
 
 
 
 Should this work?

Nope...because the value returned by mysql_query() isn't the number of
rows returned by the query...it's a pointer to the result set (which
could be empty).
 
 $f1 = rand(999,999);
 
   while($check_sid = mysql_query(SELECT * FROM 
 that_table WHERE this =
 '$f1')){
 
   $f1 = rand(999,999);
 
 }

You'll want something more like...

  do {
$f1 = rand(999,);
$check_sid = mysql_query(SELECT * from that_table WHERE
this='$f1'));
  } while (mysql_num_rows($check_sid))


---
Mark Roedel   | The most overlooked advantage to owning a
Systems Programmer|  computer is that if they foul up there's no
LeTourneau University |  law against whacking them around a little.
Longview, Texas  USA  |-- Owen Porterfield

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php