AdRock Posted April 5, 2010 Share Posted April 5, 2010 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 } Link to comment https://forums.phpfreaks.com/topic/197616-how-to-reset-counter-if-id-number-chnages/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 5, 2010 Share Posted April 5, 2010 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 } Link to comment https://forums.phpfreaks.com/topic/197616-how-to-reset-counter-if-id-number-chnages/#findComment-1037130 Share on other sites More sharing options...
AdRock Posted April 5, 2010 Author Share Posted April 5, 2010 I was at work earlier and it came to me that is what i should do. Tried to do something similar which did't work but this does perfectly....many thanks Link to comment https://forums.phpfreaks.com/topic/197616-how-to-reset-counter-if-id-number-chnages/#findComment-1037399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.