这是我的代码
$unique_ref_length = 8;
$unique_ref_found = false;
$possible_chars = "23456789BCDFGHJKMNPQRSTVWXYZ";
while (!$unique_ref_found) {
$unique_ref = "";
$i = 0;
while ($i < $unique_ref_length) {
$char = substr($possible_chars, mt_rand(0, strlen($possible_chars)-1), 1);
$unique_ref .= $char;
$i++;
}
$query = "SELECT * FROM table WHERE ref ='".$unique_ref."'";
$result = mysql_query($query) or die(mysql_error().' '.$query);
if (mysql_num_rows($result)==0) {
$unique_ref_found = true;
}
}
$ref = $unique_ref;
答案 0 :(得分:-2)
它固定无所事事,谢谢
$qry = "SELECT * FROM table WHERE token ='".$unique_ref."'";
$stm = $db->prepare($qry);
$stm->execute();
if ( $row = $stm->rowCount()==0) {
$unique_ref_found = true;
}