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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.