I have a page that has to generate a 9-digit order number and then check the db (MySQL) to see if it exists. If it already exists, it needs to generate a new order number and recheck until a unique number is created.
//MARKER
$rantruckorderid = rand(000000000,999999999);
$chkorderid = "select truckorderid from truckorders where truckorderid=".$rantruckorderid;
$chkresult = mysql_db_query($database, $chkorderid);
$foundcount = mysql_num_rows($chkresult);
if ($foundcount == 0)
{
print "<h1>Continue</h1>";
}
elseif ($foundcount == 1)
{
print "<h1>Regenerate number.</h1>";
}
In the example above, if $foundcount returns rows then I need to generate a new number. Is there a way to send the code back to //MARKER to rexecute until $foundcount returns no rows?
Is there a better way to generate a unique order number?
Brian