Stryves Posted April 16, 2009 Share Posted April 16, 2009 Can't figure out what's wrong here: $query=mysql_query("select * from current where priority > '0' and type='played' order by priority DESC, name"); $percenttotal='0'; $randomnum=rand(1,100); while($result=mysql_fetch_array($query)) { if($randomnum>=$percenttotal && $randomnum<=$result[priority]) { $winner=$result[name]; } $percenttotal=$percenttotal+$result[priority]; } Basically I'd have like 10 people, and the table would be like TABLE: CURRENT Name, Played, Priority I was hoping during the while, it would grab those with highest priority first, see if they match the random number. If they don't, then use their percentage as the starting point for the next guy, and check to see if they are above or below the number drawn. If they won, declare a winner. No errors are reported, and when I echo the $winner nothing is shown... Any ideas? Made an edit, had an accidental plural Quote Link to comment Share on other sites More sharing options...
Stryves Posted April 16, 2009 Author Share Posted April 16, 2009 nevermind, I forgot to add the percenttotal. ($randomnum>=$percenttotal && $randomnum<=$result[priority]+percenttotal) Sigh. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.