OriginalSunny Posted March 19, 2006 Share Posted March 19, 2006 Hi,I am trying to ouput data in the way i want. I have used the code below and the data is output correctly, but there are too many objects on one row. All objects are output on one row and i want to limit it to 5 objects per row, so once the array reaches 5 it begins a new row. I do however still want all objects in the array to be output. How do i alter the code to do this?? ( I know it can't be too difficult but the only way i can see is by limiting the array to 5 and this will not ouput all the objects i want). Thanks.echo"<table cellpadding='10'>"; echo "<tr>"; foreach($food_categories as $key => $subarray) { foreach($subarray as $type) { echo "<td>"; echo "<input type='radio' name='interest' value='$type'><b><img src='$type' width=100 height=100></b><br>\n";echo "</td>"; } }echo "</tr>";echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/5293-outputting-objects-correctly/ Share on other sites More sharing options...
insrtsnhere13 Posted March 20, 2006 Share Posted March 20, 2006 [code]$i = "1"; while($row = mysql_fetch_object($result)) {if ($i == "1") { echo "<tr>"; }if ($i == "3") { echo "</tr"; $i = "1"; } echo "<center><td><p align=\"center\"><a href=\"$row->url\"><img src=\"$row->url\" heigh=\"%40\" width=\"%40\" border=\"0\"></a><br>$row->caption</p></td>"; $i++;} [/code]thats what i use for my gallery, obviously you need to format it for your own needs Link to comment https://forums.phpfreaks.com/topic/5293-outputting-objects-correctly/#findComment-18947 Share on other sites More sharing options...
Barand Posted March 20, 2006 Share Posted March 20, 2006 Here's my general-purpose code for multi-col output from an array[code]$myArray = array(1,2,3,4,5,6,7,8,9,10,11,12);define ("NUMCOLS",5);$count = 0;echo "<TABLE border=1>";foreach ($myArray as $item) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$item</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}if ($count % NUMCOLS != 0) { # end row if not already ended while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";echo "<table><tr>";[/code] Link to comment https://forums.phpfreaks.com/topic/5293-outputting-objects-correctly/#findComment-19142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.