Re: Column Help Needed

From: Date: Fri, 09 Jul 2004 13:57:25 +0000
Subject: Re: Column Help Needed
Groups: php.db 
Request: Send a blank email to php-db+get-35175@lists.php.net to get a copy of this message
It seems very easy to me, Chris. Just set up a counter before the loop where you fetch your queries. Then output your HTML table structure depending on whether the counter is odd or even. You can use modulo arithmethic ($value%2) to determine that. Something like: $result = mysql_query("blah blah blah..."); $num-entries = 0; echo "<table>"; while ($item = mysql_fetch_array($result)) { $num-entries++; if ($num-entries%2 == 1) { // This is an "odd" item. echo "<tr><td>"; echo "blah"; // Whatever you need to output for your result echo "</td>"; } else { // This is an "even" item. echo "<td>"; echo "blah"; // Whatever you need to output for your result echo "</td></tr>"; } } // and finally, if the result ended on a half-row: if ($num-entries%2 == 1) echo "<td>&nbsp;</td></tr>"; // now close the table. echo "</table>"; // and we're done! .... note, I didn't test this code. But it should do what you want. -- Peter Westergaard peter@westergaard.ca

« previous php.db (#35175) next »