我有一个脚本获取注册表信息的随机数,但是,我知道如何验证该号码是否使用的最佳方式是这样的:
$pin = rand(10000, 99999);
$lookforpinsql=mysql_query("SELECT `pin` FROM `db_registery` WHERE `pin` = ".$pin);
$countpin=mysql_num_rows($lookforpinsql);
if ($countpin > 0) { $pin = rand(10000, 99999); }
$lookforpinsql=mysql_query("SELECT `pin` FROM `db_registery` WHERE `pin` = ".$pin);
$countpin=mysql_num_rows($lookforpinsql);
if ($countpin > 0) { $pin = rand(10000, 99999); }
$lookforpinsql=mysql_query("SELECT `pin` FROM `db_registery` WHERE `pin` = ".$pin);
$countpin=mysql_num_rows($lookforpinsql);
if ($countpin > 0) { $pin = rand(10000, 99999); }
我在dbase上寻找它3次,以确保它还没有使用,是否有更好的方法?