Jump to content

How do I compare 2 random numbers to entries in a table


apw

Recommended Posts

How would I compare 2 random numbers to rows in a table.  The table has 4 rows and 2 colums.  My table is setup like this: ID hp mp then has just randomly placed numbers from 0 to 5.  So far my script looks like this: I have $new_hp=rand(0,5); $new_mp=rand(0,5).  Then i query the db by $myquery=doquery("select hp,mp from users";  $myrow=mysql_fetch_array($myquery); once this is done would a while statement like while ($myrow = mysql_fetch_array($myquery) to what each line in the table has?  I would then need to compare the random numbers to those entries in the database.  Something like if($myrow[hp] == $new_hp && $myrow[mp] == $new_mp) { ?  But if the if statement isnt true it needs go back choose another random number and run same again and again until the statement is true and that is where im stuck at so any help would be greatly appreciated

Link to comment
Share on other sites

But if the if statement isnt true it needs go back choose another random number and run same again and again until the statement is true

 

If your just going to keep picking random numbers until that statement is true, why bother with the random numbers at all?  Just use $myrow['mp'] and $myrow['hp'].

 

Your going to need to better explain what your trying to do if you need more help.

 

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.