I have some code to generate a string of 3 letters followed by 3 numbers. The idea is that it generates a string, then looks in a mysql db to make sure the string doesn't exist, and if it doesn't, it accepts the code. Can anyone tell me whether the logic is sound? In other words, if it finds a match of the string in the db, will it make a different string? The code is
Code:
$success='n'; while($success=='n') { $x=1; while ($x <= 3) { $random .= rand(0,9); $x++; } $rtocode=strtolower(substr($rtoname,0,3).$random); // Check rtocode not already used $q="select rtoid from rtos where rtoid='$rtocode'"; $r=mysql_query($q) or sqlerror($q,mysql_error()); if(mysql_numrows($r)==0) { $success='y'; } }
Comment