samedi 7 février 2015

Simple While loop database search table

first of all: Thanks for all the great help I already received through finding answers to questions others posted.


I have a small and easy question for you:


I'm trying to randomly generate a number, but if it exists in the database table, it should keep generating a new numbers until it finds a unique number.


Help would be much appreciated!



$klantnr = rand(1,9);

$kn = mysql_num_rows(mysql_query('select username from users where id="'.$klantnr.'"'));

while($kn!=0){
$klantnr = rand(1,9);
}
echo $klantnr;

Aucun commentaire:

Enregistrer un commentaire