Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/50140-why-is-this-loop-not-working-mysql-php/
Share on other sites

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";
	}
}


?>

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.