...

View Full Version : mysql row output in 2 colums



macmonkey
09-04-2005, 09:05 PM
Hey everyone. I've done some searching and cant come up with my answer. Also I'm not thinking straight thanks to a "summer flu" so I figured Id ask for some help.

I've got a music reviews feature on the front page of my site. I've got my results limited to 0, 4. What I'm looking for is the results to show up:

Row 1 | Row 2
Row 3 | Row 4

Here a simple row output:


.<?
echo "<table>";
$result = mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4");
while($myrow = mysql_fetch_assoc($result)) {

echo "<tr><td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">";
echo "<h3>$myrow[title]</h3><br>";
echo "$myrow[intro_text]</td></tr>";


} echo "</table>"; ?>

Desired HTML output:

<table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>
Hope this is enough info to get an answer.

Thanks in advance

marek_mar
09-04-2005, 09:14 PM
<?
echo "<table><tr>";
$result = mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4");
for($i = 0; $myrow = mysql_fetch_assoc($result); $i++) {
echo ($i % 2) ? '</tr><tr>' : '';
echo "<td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">";
echo "<h3>$myrow[title]</h3><br>";
echo "$myrow[intro_text]</td>";


} echo "</tr></table>"; ?>

Should do the trick.

macmonkey
09-05-2005, 01:24 AM
That's very close but it's strange:


Row 1 |
Row 2 | Row 3
Row 4 |


^^^ That's what it's giving me rather than:

Row 1 | Row 2
Row 3 | Row 4

any suggestions

macmonkey
09-05-2005, 02:16 AM
I just took the echo ($i % 2); row and sent it to the bottom of the loop and it made a working difference.



<?
echo "<table><tr>";
$result = mysql_query("SELECT * FROM album_review ORDER BY id DESC LIMIT 0,4");
for($i = 0; $myrow = mysql_fetch_assoc($result); $i++) {

echo "<td><img align=\"left\" src=\"../images/album_review/$myrow[assoc_img]\" width=\"100\" height=\"100\" class=\"story\" alt=\"MISSING IMAGE\">";
echo "<b>$myrow[title]</b><br>";
echo "$myrow[intro_text]</td>";
echo ($i % 2) ? '</tr><tr>' : '';


} echo "</tr></table>"; ?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum