apw Posted February 11, 2012 Share Posted February 11, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/256869-how-do-i-compare-2-random-numbers-to-entries-in-a-table/ Share on other sites More sharing options...
kicken Posted February 11, 2012 Share Posted February 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256869-how-do-i-compare-2-random-numbers-to-entries-in-a-table/#findComment-1316901 Share on other sites More sharing options...
Psycho Posted February 11, 2012 Share Posted February 11, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/256869-how-do-i-compare-2-random-numbers-to-entries-in-a-table/#findComment-1316915 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.