Hello,
On my web site, I am running a draw that goes every 5 mins. I have a user data base that i am using to pull the info from to generate a ticket based on the ID of each person that is registered.
Here is my problem. There is only about 500 players in my game, however many have been deleted, so the ID counts go up into the 1,600's. When the code randomly draws for the winner, it picks from one, all the way up to 1,600, so if a player doesn't exist anymore, it will still pick their number, thus no one will win. This is the code I use:
//GET TOTAL NUMBER TICKETS IN THE DRAW
$tickets1 = mysql_query("SELECT FROM userdb WHERE id='$id'");
$tickets = mysql_num_rows($tickets1);
//RANDOMLY PICK WINNING TICKET NUMBER
$winningticket = rand(1,$tickets);
$winner3 = mysql_query("SELECT FROM userdb WHERE id='$winningticket'");
$winner2 = mysql_fetch_array($winner3);
mysql_query("UPDATE userdb SET tokens=tokens+1 WHERE id='$winner2[id]'");
//SEND USERNEWS TO WINNER ADVISING OUTCOME AND PRIZE
mysql_query("INSERT INTO usernews (id,user,text,time) VALUES ('','$winner2[id]','<b>$time- 5 Min Lottery:</b> Congratulations!! You have won the 5 minute Lottery Draw! - You got 1 Donator Token!','$time')");
mysql_query("INSERT INTO usernews (id,user,text,time) VALUES ('','1','<b>$time- 5 Min Lottery:</b> $winningticket won a token','$time')");
Is there something I can add so that when it Gets the total number of tickets for the draw, or Randomly picks the number, that it will only pick from people who are actually in the DB, and not all numbers between 1 and 1,600?