Re: Splitting results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I am trying to split the results from a database query into specific
> number of columns per row. I know how to create a repeat region but the
> problem is this either creates a bunch of columns next to each other or
> a bunch of rows below each other. What I want to be able to do for
> example is have the results displayed in a format of three columns per
row.
>
> Any ideas?

Try writing some code is this short answer.

Seriously, it can't take much thinking to work out that you need some kind
of nested loop to write your columns, taking care to close each open <td> &
<tr> as you go.

e.g.

for ($i = 0; $i < count ($rows); $i++)
{
    echo "<tr>";
    for ($j = 0; $j < 3; $j++)    // Three columns
    {
        echo "<td>";
        echo (isset ($rows[$i + $j])) ? $rows[$i+$j] : "&nbsp;";
        echo "</td>";
    }
    echo "</tr>";
}

But surely you could have worked this out for yourself?  This is a list for
people with problems coding in PHP *other than* not being bothered to write
code for themselves.

Mikey

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux