Jump to content

how to reset counter if id number chnages


AdRock

Recommended Posts

Say i have about 10 records for each $festivalid.  How can i get each $festivalid when it changes to restart the $counter?

 

I thought about a foreach loop but i din't know if that will work.  I just need to check if the festivalid is differnent and if it is reset it back to 1.

 

$counter=1;
while (list($eventname,$festivalid,$image,$thumb,$description,$username) = $result->fetchrow()) {
$eventname = strtolower(str_replace(' ','-',$eventname));
if ($count % NUMCOLS == 0) echo "<tr>\n";  # new row
echo "<td><div class='img-shadow'><a href='image.php?id=$festivalid&festival=$eventname&pagenum=$counter'><img src='users/$username/albums/$festivalid/thumbs/$thumb' alt='$description' title='$description' style='border:none' /></a></div></td>\n";
$count++;
$counter++;

if ($count % NUMCOLS == 0) echo "</tr>\n";  # end row
}

 

How would a human detect a change in a value? He would remember the previous value and when the new value is not the same as the last value, it changed -

 

$last_value = NULL; // remember the last value (initialize to a value that will not exist in the data)
while (list($eventname,$festivalid,$image,$thumb,$description,$username) = $result->fetchrow()) {
    if($last_value != $festivalid){
        $last_value = $festivalid; // remember the new value
       // do any special processing here when the value changes ...

    }
    // the rest of your code inside the loop

}

 

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.