Stephen Kennedy
Stephen Kennedy

Reputation: 549

Why is my loop not incrementing?

I am trying to take a subset of an mysql statements results from an if statement, and if the last one in the sequence, apply appropriate code.

I want to set up two increments and then if($secondcount > $totalcount) do something else.

MySqlNUMRows won't work as it is a subset, neither will a where clause in this case, that I can see. Can anyone see the cause?

$counting = 0;
while($thisrow = mysqli_fetch_array($sqlchangenamesresult))
{   
$change_name = $thisrow['change_name'];

#count the updating results

if(strstr($row['Content_lists'], $change_name) != FALSE)
{
    $counting++;
}   
$totalcount = $counting;

$secondcount = 0;
if(strstr($row['Content_lists'], $change_name) != FALSE)
    {

        if($secondcount > $totalcount)
        {   
            echo '<br>' .$secondcount. '<br>' . $totalcount;
        $sqlinsert .= $thisrow['change_name'];
        $sqlinsert2 .= 'Yes';
        $secondcount++;
        }
        else 
        {
            echo '<br>' .$secondcount. '<br>' . $totalcount;
        $sqlinsert .= $thisrow['change_name'] . ', ';
        $sqlinsert2 .= 'Yes, ';
        $secondcount++;
        }

    }

Upvotes: 0

Views: 82

Answers (1)

Karoly Horvath
Karoly Horvath

Reputation: 96258

$secondcount is 0, so it cannot be larger than $totalcount.

note:

  • != FALSE is incorrect
  • $totalcount always equals $counting. why have to variables?
  • $secondcount++; is in both branches.. move it out of the branch body.

Upvotes: 1

Related Questions