Display records 3 items in a row and move to next row. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Display records 3 items in a row and move to next row.

FindingAngelsFindingAngels Posts: 1Member
Hi buddies,

I would like to seek help on how to display 3 items in a row and move to next row. I have a short piece of code here and hope someone out there could help me on this.

Let say I have 4 records in database :


[color=Red][b]<?
$query = "Select * from products";
$result = $db_mysql->query($sql);
while ($row = mysql_fetch_row($result))
{
for($i=0; i<2; $i++)
{
?>[/b][/color]
[b][color=Red]<? echo $row[id] ?>[/color][/b]
[b][color=Red]<?
}

}
?>[/color][/b]


The output display is 1 2 3 4 but I want it to be displayed like this

1 2 3
4 5 6
7 8 9
10 11 12

I would greatly appreciate if someone could help me on this.

Thank you buddies.




Comments

  • GabeGabe Posts: 61Member
    For example:
    [code]
    <?php
    $query = "Select * from products";
    $result = $db_mysql->query($sql);
    $i = 0;
    while ($row = mysql_fetch_row($result)) {
    if ($i % 3 == 0)
    echo "";
    echo "".$row["id"]."";
    $i++;
    }
    ?>
    [/code]
Sign In or Register to comment.