elev Posted February 9, 2008 Share Posted February 9, 2008 Hi, I've got code working that retrieves rows from my mysql database and displays the 4 results in a 1x4 table. The code is basically <table> while($row=mysql_fetch_array($results)){ echo "<tr><td>" echo $row['results']; echo "</td></tr>"; } </table> What I want to do is have the data displayed like this instead: <table> <tr><td>Result1</td><td>Result2</td></tr> <tr><td>Result3</td><td>Result4</td></tr> </table> I think there is an easy solution, but I don't really have much experience. Thanks in advance for the help! Link to comment https://forums.phpfreaks.com/topic/90176-putting-4-mysql-rows-into-a-2x2-table/ Share on other sites More sharing options...
pocobueno1388 Posted February 9, 2008 Share Posted February 9, 2008 This is such a common question there is a topic specifically for it that explains how to do it. http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Link to comment https://forums.phpfreaks.com/topic/90176-putting-4-mysql-rows-into-a-2x2-table/#findComment-462406 Share on other sites More sharing options...
sasa Posted February 9, 2008 Share Posted February 9, 2008 try $num_colum = 2; <table> while($row=mysql_fetch_array($results)){ echo "<tr><td>" echo $row['results']; echo "</td>; for ($i = 1; $i < $num_colum; $i++) { echo '<td>', $row=mysql_fetch_array($results) ? $row['results'] : ' ', '</td> } echo "</tr>"; } </table> Link to comment https://forums.phpfreaks.com/topic/90176-putting-4-mysql-rows-into-a-2x2-table/#findComment-462441 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.