Jump to content

[SOLVED] Pulling a percent based random from the database and calculating results


Stryves

Recommended Posts

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 :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.