Jump to content

[SOLVED] Show data in table


steviez

Recommended Posts

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

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>";

?>

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.