View Full Version : While Loop in Table
onestopplay
07-01-2009, 07:52 PM
So I have a While Loop with my MySQL info.
That makes a list of all my data but what if I want it to display in table with two columns? That way its in columns and not a list.
If you need more explaination, ask.
THANKS FOR THE HELP!!
bluewalrus
07-01-2009, 09:32 PM
write the <table> outside of the while and then this <tr><td></td><td></td></tr>inside then when the while closes </table> if you want more specific post your code or a sample of it
onestopplay
07-02-2009, 02:08 AM
Here's my code:
$result = mysql_query("SELECT * FROM videos ORDER BY title");
while($row = mysql_fetch_array($result))
{
echo "<a href='playvideo.php?videoid=" . $row['videoid'] . "'>" . $row['title'] . "</a>";
echo "<BR>";
}
So how would I put into a table? I didn't really understand what you said.
I want it so I have:
title 1 | title 2
title 3 | title 4
title 5 | title 6
as a table.
THANKS!!
bluewalrus
07-02-2009, 03:03 AM
Something like this i think should do it
$result = mysql_query("SELECT * FROM videos ORDER BY title");
?>
<table border = "0">
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr><td><a href="playvideo.php?videoid=<?=$row['videoid']?>"><?=$row['title']?></a></td><td>TITLE 2 COMES FROM?</td></tr>
<?php
}
?>
</table>
onestopplay
07-02-2009, 11:18 PM
Unfortunately, I tried that and it didn't work. If anyone wanted the answer though that I found, here it is:
<table>
$n = 0;
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
if ($n == 0) {
echo '<tr>';
}
echo "<td>DATA IN TABLE HERE</img></td>
<td width=\"20px\"></td>\n";
$n++;
if ($n == 2) {
echo '</tr>';
$n = 0;
}
}
if ($n == 1) {
echo '<td></td>
<td width=\"20px\"></td>
</tr>';
}
</table>
-http://www.dmcinsights.com/phorum/read.php?9,39512
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.