What im trying to do here is generate a random number. Now i want to validate if the randomnumber exists in the database and if it existed it should generate another random number and validate it again. I tried using if (mysql_num_rows>0) but its not the right way.
Someone pls help me on this. Thanks!
PHP CODE:
$randomnumber= rand(1000,9999);
$sql = "SELECT * FROM table WHERE column= '$randomnumber'";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);
//while loop
WHAT I DID:
$randomnumber= rand(1000,9999);
$sql = "SELECT * FROM table WHERE column= '$randomnumber'";
$result = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result);
if ($numrows>0)
{
$randomnumber =rand(1000,9999);
$sql = "SELECT * FROM table WHERE column= '$randomnumber'";
$result = mysql_query($sql) or die(mysql_error());
}
"double quotes in query? And why are you saying it is not the right way?