Forum Moderators: coopster

Message Too Old, No Replies

Stacking TWO tr's in with Echo, NOOB question

I'm echoing a table and need to stack two tr's

         

ball4121

10:43 am on Dec 2, 2007 (gmt 0)

10+ Year Member



I have a very noob question and I am completely lost. Of course I tried pasting the php code twice, but obviously I got repeats in the mysql query.

<table width="100%" height="85" cellspacing="0" cellpadding="0" border="0" align="center">
<tr>

<?PHP
$q=mysql_query("SELECT Name AS feat_name, URL AS feat_url, Thumbnail AS feat_thumb, RAND() * Weight AS Weighted FROM `featured` ORDER BY Weighted DESC LIMIT 6");
while ($line=mysql_fetch_assoc($q)) {
echo "<td align=\"center\" valign=\"middle\">";
echo "<a href=\"$line[feat_url]\" class=\"maintext\" target=\"_blank\"><img src=\"/images/$line[feat_thumb]\" class=\"thumbnail\" align=\"middle\"><br> <small>$line[feat_name]</small></a>";
echo "</td>";
}

?></tr>
</table>

Right now i'm displaying [1][2][3][4][5][6]

When I want
[1][2][3]
[4][5][6]

Thank you!

Habtom

10:54 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$get_tr = 0;
while ($line=mysql_fetch_assoc($q)) {
if ($get_tr == 0) {
echo "<tr>";
}

echo "<td align=\"center\" valign=\"middle\">";
echo "<a href=\"$line[feat_url]\" class=\"maintext\" target=\"_blank\">
<img src=\"/images/$line[feat_thumb]\" class=\"thumbnail\" align=\"middle\">
<br>
<small>$line[feat_name]</small>
</a>";
echo "</td>";

if ($get_tr == 0) {
echo "</tr>";
}

if ($get_tr < 2) {
$get_tr++;
} else {
$get_tr = 0;
}
}

ball4121

11:36 am on Dec 2, 2007 (gmt 0)

10+ Year Member



Hmmm now it's acting pretty weird

It's showing like this

[1] .............
[2] ............. [3]
[4] .............
[5] ............. [6]

Wish I could show you

Habtom

11:40 am on Dec 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if ($get_tr == 0) {
echo "</tr>";
}

to

if ($get_tr == 2) {
echo "</tr>";
}

This will give you pretty much of the output, test it and you will need to handle a few exceptions.

ball4121

11:47 am on Dec 2, 2007 (gmt 0)

10+ Year Member



if ($get_tr == 5) {
echo "</tr><tr><td>&nbsp;</td></tr>";
}

if ($get_tr < 5) {
$get_tr++;
} else {
$get_tr = 0;
}
}

Got it to work, thanks Habtom!