If you use the following code it should work well. I used 2 counters, one for the columns and one for the row. It's a bit messy but it works.
Cheers NB: Code is untested but copied from a working example with unnecessary bits removed. <? echo "<table>\n"; $counterRow = 0; $counterCol = 0; $counterResults = mysql_num_rows($result); for ($i = 0; $i < $counterResults; $i++) { if (($colCounter < 3) && ($counterRow == 0)) { echo " <tr>\n"; $counterRow = 1; } echo " <td>Column Data</td>\n"; $counterCol++; if ($counterCol == 3) { echo " </tr>\n"; $counterCol = 0; $counterRow = 0; } } echo "</table>\n"; ?> -----Original Message----- From: SpamSucks86 [mailto:[EMAIL PROTECTED]] Sent: Tuesday, 19 February 2002 12:35 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: [PHP] RE: [PHP-DB] I cant get the logic for this... 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 <?php $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 row 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; while($oRow) { //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 >show >3 results per row of the table... I.e.: > >Table >TR >TD = result1 /TD TD result2 /TD TD = result3 /TD >/TD >/TR >TR >TD = result4 /TD TD result5 /TD TD = result6 /TD >/TD >/TR >TR >TD = result7 /TD TD resultempty /TD TD = resultempty /TD >/TD >/TR >/table > >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 >http://www.davecarrera.com > > > > >-- >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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php