I had this same problem. It's very aggravating. Jason G's solution won't
work, because $oRow will always be true as long as there is more
results, NOT if there are less than 3 results left.

Why don't you true something like this

$nWidth = 3;
$numrows = mysql_num_rows($result);

//Now take the number of rows and figure out the number of extra cells
not divisible by $nWidth
$tmp = $numrows % $nWidth;

//Cut off the extra number of cells
$numevenrows = $numrows - $tmp;

//Let's bring the number down to something easier to work with (number
of even rows)
$numevenrows = $numevenrows/$nWidth;

//$tmp still contains the number of cells which don't fall evenly into a

while ($numevenrows > 0) {
        //echo your row with 3 cells
        $numevenrows = $numevenrows - 1;

if ($numrows == 2) {
        //Write the last row with only two cells. You might want to just
close the old table and make a new one and center it so that those two
cells are centered, or you could use colspan="2" in the HTML so that one
of the cells spans more.

elseif ($numrows == 1) {
        //same thing

This code is definitely untested, but I think you should understand the
logic behind it, I did more commenting than I did coding.

-----Original Message-----
From: Jason G. [mailto:[EMAIL PROTECTED]] 
Sent: Monday, February 18, 2002 9:11 AM
To: Dave Carrera; [EMAIL PROTECTED]
Subject: Re: [PHP-DB] I cant get the logic for this...

$nWidth = 3;
$oRow = TRUE;

         //Write tr here
         for($i=0; $i<$nWidth; $i++)
                 $oRow = mysql_fetch_object($dbResult);
                 //Write <td></td> here
         //write /tr here

At 12:06 PM 2/18/2002 +0000, you wrote:
>Hi all,
>I want to display return results from my query (which works fine)
>In I tidy way on screen.
>So my result returns say seven results, I have a table, and I want to
>3 results per row of the table... I.e.:
>TD = result1 /TD  TD result2 /TD TD = result3 /TD
>TD = result4 /TD  TD result5 /TD TD = result6 /TD
>TD = result7 /TD  TD resultempty /TD TD = resultempty /TD
>The last two td in row 3 are empty because result found 7 results.
>This cant be fixed so echo statements wont work as the result could
>Be 3 or 10 or 56 or whatever.....
>As Always your help and or guidance in this matter is appreciated.
>Dave Carrera
>Php / MySql Development
>Web Design
>Site Marketing
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php

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

Reply via email to