Hi, all.
I am trying to get resuls from the database to output into a 3-column table. Maybe I’ve been staring at this piece of code for too long, but I cannot see where/what I am doing wrong.
What ouputs is a 3-column table, but all results are showing up only in the first column, anyway.
Somebody, smack me! (THANKS!)
[code=php]
echo “<table border=”1″>n”;
$query = “SELECT * FROM `names`”;
$result = mysql_query($query, $linkID);
while ( $row = @mysql_fetch_array($result) )
{
$name = “”.$row[‘first’].” “.$row[‘last’].””;
$names = array($name);
$cols = 3;
$total = count($names);
$rows = ceil($total/$cols);
for ($row=1; $row <= $rows; $row++)
{
$cell = 0;
echo “<tr>n”;
for ($col=1; $col <= $cols; $col++)
{
echo “<td>n”;
if ($col===1)
{
$cell += $row;
echo $names[$cell – 1];
}
else
{
$cell += $rows;
echo $names[$cell – 1];
}
echo “</td>n”;
}
echo “</tr>n”;
}
}
echo “</table>n”;