I want to generate a random number and check to see if it exists in the rnum field of all my tables (4 of them). If it exists in any of them, then I want to generate a new random number over and over until a unique one is generated. This code works when a single table name is used in place of the wildcard.
$row['rcnt']=1;
while($row['rcnt']>0)
{
$random_number = rand(1,10000);
$result = mysql_query("SELECT COUNT(rnum) as rcnt FROM * WHERE rnum='".$random_number."'") or die(mysql_error());
$row = mysql_fetch_array($result);
}
With the wildcard I get an error of "check your mysql syntax near '* ...
Just for laughs, I also tried this (for 2 tables):
$row['rcnt']=1;
$row2['rcnt2']=1;
while($row['rcnt']>0&&$row2['rcnt2']>0)
{
$random_number = rand(1,10000);
$result = mysql_query("SELECT COUNT(rnum) as rcnt FROM table1 WHERE rnum='".$random_number."'") or die(mysql_error());
$row = mysql_fetch_array($result);
$result2 = mysql_query("SELECT COUNT(rnum) as rcnt2 FROM table2 WHERE rnum='".$random_number."'") or die(mysql_error());
$row2 = mysql_fetch_array($result2);
}
Also, I was hoping this would work (commas):
$result = mysql_query("SELECT COUNT(rnum) as rcnt FROM table1,table2,table3,table4 WHERE rnum='".$random_number."'") or die(mysql_error());
Thanks in advance.