PDA

View Full Version : Splitting Data Results into Rows


SixteenOhNine
05-08-2006, 02:43 AM
I am currently using vBulletin's pagination and have it working correctly, however, my current results are displaying in a single row and then links to the next page are shown. I'd like to expand this.

Given I am using pagination and would like to display 4 results per row and once it hits 4 results, split the data into a new row such as below.

I have 9 results.

x x x x

x x x x

x

How would I go about splitting this off as the results are called?

Xorlev
05-08-2006, 02:52 AM
Keep a running count. Here's a non-vBulletin example made with a loop:

for ($i = 0; $i < 12 ; $i++) {
$x++;

if ($x == 5) {
$x = 0;
echo '<br />';
}

echo 'Element ' . $i + 1 . ' ';
}

Basically all this code does is create a line break every 5 elements. Hopefully you can apply this towards your needs.

Code Monkey
05-08-2006, 03:16 AM
This is what the modulus % operator is for.


$columns = 4;
for($i = 0; $i < $somevalue; $i++)
{
echo $output[i];
if($i % $columns == 0)
{
echo '<br />'; //or </tr><tr> or whatever you need.
}
}