Re: I cant get the logic for this...

From: Date: Tue, 19 Feb 2002 17:41:43 +0000
Subject: Re: I cant get the logic for this...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-85467@lists.php.net to get a copy of this message
<?php $nWidth = 3; // desired table width $nPos = 0; // current-column counter // do database query $res = mysql_query(???); // start table echo "<table>"; // while there is data... while($row = mysql_fetch_object($res)) { // begin new row if appropriate. // NOTE: Of necessity, I separate this from the // end-of-row test; otherwise, a query returning // an exact multiple of the table width would // result in a table with an empty final row. if (0 == $nPos) echo "<tr>"; // write a cell and increment location echo "<td>".your_stuff."</td>"; $nPos++; // end row if appropriate and reset location if ($nWidth == $nPos) { echo "</tr>"; $nPos = 0; } } // calculate padding needed for final row // NOTE: if-and-only-if padding is required, // the row must be terminated; otherwise the // row must have already been terminated. $nEmpty = $nWidth - ($nPos+1); if ($nEmpty > 0) echo "<td colspan='$nEmpty'>&nbsp;</td></tr>"; // end table echo "</table>"; ?> > >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

« previous php.general (#85467) next »