Forum Moderators: coopster
For example, here's the code im using now, which displays an unlimited number of columns on only one row
$result7=mysql_query("SELECT journal_id, MAX(entry_timestamp) AS entry_timestamp FROM journal_entries GROUP BY journal_id ORDER BY entry_timestamp DESC");
while ($i = mysql_fetch_array($result7)) {
$mainpic = mainpic($i['journal_id']);
$time = backwhen($i['entry_timestamp']);
$name = truncate($i['journal_id']); echo '<td style="padding: 10px; border: 1px solid #0056a1; vertical-align: top; background: url(\'topblue.jpg\') repeat-x;"><center><b><a href="http://www.example.com/profiles/'.$i['journal_id'].'">'.$name.'</a></b><br/><br/><a href="http://www.example.com/users/'.$i['journal_id'].'">'.$mainpic.'</a><div style="color: red; font-size: 9px;">'.$time.' ago</div></center></td><td width="5px"></td>';
}
So this displays a very long table row of many td's. I'd like help figuring out a way to put some <tr>'s in there after 7 td's
Does anyone know how to do this?
$qty="7";$result7=mysql_query("SELECT journal_id, MAX(entry_timestamp) AS entry_timestamp FROM journal_entries GROUP BY journal_id ORDER BY entry_timestamp DESC");
$nb="0";
while ($i = mysql_fetch_array($result7)) {
$mainpic = mainpic($i['journal_id']);
$time = backwhen($i['entry_timestamp']);
$name = truncate($i['journal_id']);if($nb % $qty == "0") {echo '</tr><tr>';}
echo '<td style="padding: 10px; border: 1px solid #0056a1; vertical-align: top; background: url(\'topblue.jpg\') repeat-x;"><center><b><a href="http://www.example.com/profiles/'.$i['journal_id'].'">'.$name.'</a></b><br/><br/><a href="http://www.example.com/users/'.$i['journal_id'].'">'.$mainpic.'</a><div style="color: red; font-size: 9px;">'.$time.' ago</div></center></td><td width="5px"></td>';
$nb++;}
Use $nb to count the rows (note $nb++ to increment the $nb value). Then if $nb is a multiple of 7 (e.g. 7, 14, 21, etc.), then add </tr><tr>.
Not tested! At least, you know the way to proceed.
Give it a try and report back.