scrubbicus Posted April 29, 2009 Share Posted April 29, 2009 Hey, so I have some categories that I have stored in a MySQL table. I want to loop through that table but create a two column menu. I tried this. while($row = mysql_fetch_array($results)) { <tr> <td> $row['name']; </td> <td> $row['name']; </td> </tr> } but as I found out, and should have been obvious to me, it just gives that name twice so I have two of the same category on each row. Link to comment https://forums.phpfreaks.com/topic/156074-creating-a-two-column-table-through-looping/ Share on other sites More sharing options...
Sulman Posted April 29, 2009 Share Posted April 29, 2009 Hi, Try this: <?php $count=1; $number_of_columns=2; //The required number of columns while ($rowWork = mysql_fetch_array($resultWork)){ if ($count==1){ echo "<tr>"; //Open the row } echo "<td valign=\"top\">".$row['column']."</td>"; if ($count==$number_of_columns){ echo "</tr>"; //Close the row if we have reached the required number of columns $count=0; //Set the counter back } $count++; } ?> Link to comment https://forums.phpfreaks.com/topic/156074-creating-a-two-column-table-through-looping/#findComment-821622 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.