(SOLVED) [PHP] How can I output a query in a table with the output in multiple columns?

From: Date: Fri, 21 Jun 2002 12:42:19 +0000
Subject: (SOLVED) [PHP] How can I output a query in a table with the output in multiple columns?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-103264@lists.php.net to get a copy of this message
Hello John, PHP I used your script almost everything is worked. Thanks. Here is the script if someone will need it :) <? $count = 1; $Num_Across = 4; $Width = floor(100 / $Num_Across); while($row = MySQL_fetch_array($result)) { //create first cell $tttt = $count / $Num_Across; echo "<td width='".$Width."'>".$row['name']."</td>\n"; //keep a count so you know when to start a new row if(round($tttt) == $tttt) { echo "</tr><tr>\n"; } $count++; }; //this will finish the table, i.e. if you only have one //name on last row, this will fill in the remaining table //cells $left = $Num_Across - (--$count % $Num_Across); for($x=0;$x<$left;$x++) { echo "<td>&nbsp;</td>\n"; }; echo "</tr>"; echo "</table>"; ?> Friday, June 21, 2002, 3:42:24 PM, you wrote: >> I've got the following situation: I have a list of items i want JH> placed >> in side-by-side columns in a table like this: >> >> name name name name >> name name name name >> name name name name >> name name name name >> >> and so on. How can I do it? Name is a string in the database. JH> You can try something like this: JH> <? JH> $Count = 1; JH> $Num_Across = 4; JH> $Width = floor(100 / $Num_Across); JH> //start table and first row JH> echo "<table width='100%'>\n"; JH> echo "<tr>\n"; JH> while($row = MySQL_fetch_array($result)) JH> { JH> //create first cell JH> echo "<td JH> width='$width'>".$row['name']."</td>\n"; JH> //keep a count so you know when to start a new row JH> if($count % $Num_Across == 0) JH> { $retval .= "</tr><tr>\n"; } JH> $count++; JH> } JH> //this will finish the table, i.e. if you only have one JH> //name on last row, this will fill in the remaining table JH> //cells JH> $left = $Num_Across - (--$count % $Num_Across); JH> for($x=0;$x<$left;$x++) JH> { echo "<td>&nbsp;</td>\n"; } JH> That last part isn't tested. I used a different method, but hopefully JH> this gives you an idea. JH> ---John Holmes... -- Best regards, Latex mailto:freeman@submission.org.ru

« previous php.general (#103264) next »