RE: [PHP] formating output

From: Date: Fri, 17 Dec 2004 20:39:32 +0000
Subject: RE: [PHP] formating output
Groups: php.general 
Request: Send a blank email to php-general+get-204625@lists.php.net to get a copy of this message
[snip] this structure prints out a table with a new row for each item <table > <? While ( $results = mysql_fetch_array($pointer)) { print "<tr><td ><$results[1] </td></tr>" ; } ?> </table> what I want to do is print out a table 4 columns wide and however many rows high needed to run through the data HOW do I loop through the array and get <td>data</td> printed 4 times then a new row started and then 4 more <td> cells printed, etc [/snip] Is the data all in one row in the database? <?php $results = mysql_fetch_array($pointer) print "<tr>\n; for($i = 0; $i < count($results); $i++){ if(0 = $i%4){ print "<td>" . $results[$i] . "</td>\n</tr>\n<tr>\n"; } else { print "<td>" . $results[$i] . "</td>\n"; } } print "</tr>"; ?> NOT TESTED and may give too many <tr> tags. You'll need to test for total data cells returned

« previous php.general (#204625) next »