I tried to generate random number and check it in DB if it exist, then try again until the result obtained then break using the following code
But its not working, I don't know where is the issue with while loop
<?
$digit=mt_rand(11, 999);
$sql=mysqli_query($connect, "SELECT `number` FROM `db_name` WHERE `number` =='$digit' ");
while($num=mysqli_num_rows($sql))
{
if($num==1)
{
echo "Not good";
}
else
{
echo "Good ".$digit;
break;
}
}
?>
Also I tried this code but when the number is available in DB, the script stop and not trying to generate another number
<?
$digital=mt_rand(11, 999);
$sql=mysqli_query($connect, "SELECT `number` FROM `db_name` WHERE `number` ='$digital'");
$i=0;
while($i<=10000)
{
$num=mysqli_num_rows($sql);
if($num==1)
{
$i++;
}
else
{
echo "Good ".$digital;
break;
}
}
?>
die(mysql_error)on debug mode. What error are you getting will make easier to understand issue.