Random Account Number Generation
Posted: Tue Oct 14, 2003 8:29 am
Here's what I've wrote so far:
Okay, so that'll work fine. But what would I do if the account number generated matched another one and returened false? How can I put into a loop and keep on generating and checking until I get a valid number.
Though it might be impossible to get a duplicate, I just wouldn't want to take risks in having two different accounts with the same number.
-Nay
Code: Select all
<?php
$numbers = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
for($i=0;$i<9;$i++) {
$number = array_rand($numbers, 1);
$rand_acc .= $number;
}
$q = "SELECT * FROM customers WHERE acc_no = '$rand_acc'";
$r = mysql_query($q, $connection);
if(mysql_num_rows($r) == "0") {
return TRUE;
} else {
return FALSE;
}
?>Though it might be impossible to get a duplicate, I just wouldn't want to take risks in having two different accounts with the same number.
-Nay