/    Sign up×
Community /Pin to ProfileBookmark

output results into 3-column table

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”;
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Daria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...