On Sun, 17 Aug 2003 15:47:04 -0400, you wrote:

>I'm trying to take a paged result set and divide it into two chunks for
>displaying on the page. Basically making something that looks like a typical
>thumbnail gallery. I'm limiting my result set to 6 records and want to
>display it as 2 rows of 3 cells with a record in each cell. I've had no
>trouble getting my result set, paging etc. I'm not having much luck
>splitting my result into 2 chunks. I've tried nestling 'while' statements
>with a number of arguments and either end up with no results or a loop that
>seemingly never ends. That lead me to looking at some other apps which
>seemed to use a variety of ways to achieve what I want. That lead me to
>looking at 'for' and 'foreach' in the php manual. And that lead me to being
>more confused than I was before I started ;) Sometimes there's just too many
>ways to skin a cat, eh!
>
>Below, I've include a rather lengthy bit of pseudo code that represents
>basically where I'm at now. This particular version returns no results,
>though I know it's just the nestled while's that are causing this. The
>results are there. My research makes me think that I should replace the
>nestled while's with 'foreach's. I was kind of hoping that before I spend a
>few hours trying to puzzle out how to use the 'foreach's correctly that
>somebody would venture an opinion as to whether or not that would be the way
>to go.

$data = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H');
$rowlength = 3;

echo ("<table>");
for ($i = 0; $i < sizeof ($data); $i += $rowlength)
{
        echo ("<tr>");
        for ($j = 0; $j < $rowlength; $j++)
        {
                if (isset ($data[$i+$j]))
                {
                        echo ("<td>{$data[$i+$j]}</td>");
                } else {
                        echo ("<td>&nbsp;</td>");
                }
        }
        echo ("</tr>");
}
echo ("</table>");


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

Reply via email to