steviez Posted May 18, 2008 Share Posted May 18, 2008 Hi, I am making some code for a online users box and need to get the results to display horizontally but i cant seem to get it to work. The code below only seems to show the results vertically: <?php echo "<table width=\"250\" border=\"0\">"; while($online = mysql_fetch_array($online_users)){ echo "<tr>"; echo "<td class=\"sc_text\">".$online['username']."</td>"; echo "</tr>"; echo "<tr>"; echo "<td><img src=\"".$online['profile_picture']."\" border=\"0\" alt=\"\" width=\"250\" height=\"250\" /></td>"; echo "</tr>"; } echo "</table>"; ?> Can someone please point me in the right direction Thanks Link to comment https://forums.phpfreaks.com/topic/106216-solved-show-data-in-table/ Share on other sites More sharing options...
Barand Posted May 18, 2008 Share Posted May 18, 2008 sample <?php include 'db.php'; define ("NUMCOLS",5); $res = mysql_query("SELECT col1, col2 FROM mytable"); $count = 0; echo "<TABLE border=1>"; while (list($col1, $col2) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$col1<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row } # end row if not already ended if ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n"; } echo "</TABLE>"; ?> Link to comment https://forums.phpfreaks.com/topic/106216-solved-show-data-in-table/#findComment-544431 Share on other sites More sharing options...
steviez Posted June 6, 2008 Author Share Posted June 6, 2008 Thanks for this code it works great! How could i get this code to work with pagination? Link to comment https://forums.phpfreaks.com/topic/106216-solved-show-data-in-table/#findComment-559039 Share on other sites More sharing options...
Barand Posted June 6, 2008 Share Posted June 6, 2008 Just add a LIMIT x,y clause to the end of query Link to comment https://forums.phpfreaks.com/topic/106216-solved-show-data-in-table/#findComment-559119 Share on other sites More sharing options...
steviez Posted June 11, 2008 Author Share Posted June 11, 2008 Thanks for all your help Link to comment https://forums.phpfreaks.com/topic/106216-solved-show-data-in-table/#findComment-563233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.