silkfire Posted February 3, 2012 Share Posted February 3, 2012 Hi all, does anyone know how to perform this, or if it's even possible? I need every 6th row to be a GROUP BY of the following 5 rows, they all share a common group_id so that's what the GROUP BY is performed on. 1. GROUP BY group_id 2. item #1 3. item #2 4. item #3 5. item #4 6. item #5 7. GROUP BY group_id 8. item #6 ... and so on Link to comment https://forums.phpfreaks.com/topic/256322-group-by-every-6th-row/ Share on other sites More sharing options...
trq Posted February 3, 2012 Share Posted February 3, 2012 Sorry, but your post makes little sense. Link to comment https://forums.phpfreaks.com/topic/256322-group-by-every-6th-row/#findComment-1313972 Share on other sites More sharing options...
silkfire Posted February 3, 2012 Author Share Posted February 3, 2012 What part is it you don't understand? The first row is a GROUP BY, like a summary of the five following rows, which share the same group_id. First comes a summary row, then 5 rows, and it repeats until all rows matching are retrieved. Link to comment https://forums.phpfreaks.com/topic/256322-group-by-every-6th-row/#findComment-1313989 Share on other sites More sharing options...
cyberRobot Posted February 3, 2012 Share Posted February 3, 2012 To perform a special action every time the 6th item is reached (and the first item), you could do something like this: <?php //CREATE AN ARRAY OF VALUES TO EXPERIMENT WITH $value_array = array(); for($i=1; $i<=15; $i++) { $value_array[] = rand(1,500); } //LOOP THROUGH THE TEST VALUES for($i=0; $i < count($value_array); $i++) { if($i%6 == 0) { $groupBy = true; } //for every 6th item, we need to group by (includes the first item) else { $groupBy = false; } print ($groupBy) ? "<div>$i: Group By - $value_array[$i]</div>" : "<div>$i: $value_array[$i]</div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/256322-group-by-every-6th-row/#findComment-1314024 Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2012 Share Posted February 3, 2012 I suspect you actually want to output a heading every time the group id changes, followed by the data under that heading. If so, see the logic in this post - http://www.phpfreaks.com/forums/index.php?topic=349740.msg1650897#msg1650897 Link to comment https://forums.phpfreaks.com/topic/256322-group-by-every-6th-row/#findComment-1314042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.