...

View Full Version : Insert <hr> after every 6th mysql_fetch_array row



optimus203
03-20-2010, 05:10 PM
I have a mysql_fetch_array result that produces 120 or so rows. To help make the resulting table more readable, I would like to insert a <hr>, or some graphic, after every 6th row of the resulting table. Any ideas how to do so? Here's the code I've got for the mysql_fetch_array.



echo '<table class="db_t_res">\n';

if($result)
{
while($row = mysql_fetch_array($result))
{
echo '<tr>\n
<td style="width:10%;">'.
echo $row['year'];
echo '</td>\n
<td style="width:30%;">';
echo $row['industry'];
echo '</td>\n
<td style="width:60%;">';
echo $row['emissions'];
echo '</td>\n
</tr>\n';
}
}

echo '</table>\n';

met
03-20-2010, 05:27 PM
<?php
echo '<table class="db_t_res">\n';

if($result) {

$i = 0; /* var */
while($row = mysql_fetch_array($result)) {

if($i==6) {
echo '<tr><td colspan="3"></td></tr>';
$i=0;
}
echo '<tr>\n
<td style="width:10%;">';
echo $row['year'];
echo '</td>\n
<td style="width:30%;">';
echo $row['industry'];
echo '</td>\n
<td style="width:60%;">';
echo $row['emissions'];
echo '</td>\n
</tr>\n';

$i++; //inc $i

}
}

echo '</table>\n';
?>


untested

abduraooft
03-20-2010, 05:34 PM
echo '<table class="db_t_res">\n';

if($result)
{
$i=0;
while($row = mysql_fetch_array($result))
{
printf( "<tr %s>\n
<td style=\"\">",($i%6==0?'class="hr"':''));
echo $row['year'];
echo "</td>\n
<td style=\"width:30%;\">";
echo $row['industry'];
echo "</td>\n
<td style=\"width:60%;\">";
echo $row['emissions'];
echo "</td>\n
</tr>\n";

}
}

echo '</table>\n';

tr.hr td{
background:#ccc;
}

met
03-20-2010, 05:34 PM
scratch that, use abduraoofts version !



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum