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

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.

 

I'm with Kicken on this. From what I understand you want to generate two random numbers and then try to find a matching record in your table. It would make more sense to simply select a random entry from your table. Then use the values from that record.

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.