Split MySQL result into groups of 4

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ghogilee
Forum Newbie
Posts: 19
Joined: Tue Apr 07, 2009 8:45 am
Location: Novi Sad, Serbia

Split MySQL result into groups of 4

Post by ghogilee »

Maybe today my brain isn't much of use :) but I need help to split mysql result into groups of 4 like

result1
result2
result3
result4
(and here goes some delimiter like <hr/> or something like that..)
result5
result6
result7
result8
(delimiter again)
.. etc to the end of the mysql array...
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Split MySQL result into groups of 4

Post by Darhazer »

Code: Select all

 
$count = mysql_num_rows($result);
for ($i = 0; i < $count; $i++) {
   if ($i != 0 && $i % 4 == 0) echo '<hr>';
   // the other code
}
ghogilee
Forum Newbie
Posts: 19
Joined: Tue Apr 07, 2009 8:45 am
Location: Novi Sad, Serbia

Re: Split MySQL result into groups of 4

Post by ghogilee »

Great!!! Thank you very much! :drunk:
Post Reply