lilman Posted May 5, 2007 Share Posted May 5, 2007 The objective with this do while loop is to pull all the possible candidates to vote on, but than test to make sure you haven't already voted on that person, if you haven't, it should display the picture. do { // Pull all candidates from DB $sql = "SELECT * FROM pandoris_hotornot_options WHERE gender = '$gender'"; $run = mysql_query($sql); $numrow = mysql_num_rows($run); // Put all the results in an array for ($i=0; $i <$numrow; $i++) { $row=mysql_fetch_array($run); $ids[$i]=$row['user_id']; $names[$i]=$row['user_name']; $path[$i]=$row['path']; $comments[$i]=$row['comments']; } // Randomly pick a number $number=rand (0, ($numrow-1)); // Check another DB which stores candidates id's and the rater id's. $checksql = "SELECT * FROM pandoris_hotornot_ratings WHERE canidate_id = '$number' AND rater_id = '$user_id'"; $checkrun = mysql_query($checksql); $check_num_rows = mysql_num_rows($checkrun); // If it comes back 0 that means they haven't voted on that person yet. if($check_num_rows == "0") { $go_on = "no"; } else { $go_on = "yes"; } } // If $check_num_rows equals 0 then it should $go_on should say no, thus, stopping the loop while($go_on == "yes"); I cannot seem to understand why it isn't working right. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/50140-why-is-this-loop-not-working-mysql-php/ Share on other sites More sharing options...
MadTechie Posted May 5, 2007 Share Posted May 5, 2007 try <?php $go_on = "yes"; // If $check_num_rows equals 0 then it should $go_on should say no, thus, stopping the loop while($go_on == "yes") { // Pull all candidates from DB $sql = "SELECT * FROM pandoris_hotornot_options WHERE gender = '$gender'"; $run = mysql_query($sql); $numrow = mysql_num_rows($run); // Put all the results in an array for ($i=0; $i <$numrow; $i++) { $row=mysql_fetch_array($run); $ids[$i]=$row['user_id']; $names[$i]=$row['user_name']; $path[$i]=$row['path']; $comments[$i]=$row['comments']; } // Randomly pick a number $number=rand (0, ($numrow-1)); // Check another DB which stores candidates id's and the rater id's. $checksql = "SELECT * FROM pandoris_hotornot_ratings WHERE canidate_id = '$number' AND rater_id = '$user_id'"; $checkrun = mysql_query($checksql); $check_num_rows = mysql_num_rows($checkrun); // If it comes back 0 that means they haven't voted on that person yet. if($check_num_rows == "0") { $go_on = "no"; } else { $go_on = "yes"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50140-why-is-this-loop-not-working-mysql-php/#findComment-246194 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.