How to change background color for last render row i开发者_运维技巧n while loop ....
that is
row1
row2
**row3**
If row4 is added then it should
row1
row2
row3
**row4**
that is star represents some bgcolor red...
this loop am following,,,, $i = 1; while ($row = mysql_fetch_assoc($sql)) {
$out_data[] = "<p>$i {$row['news']} </p>";
$i++;
}
$divider = '<div class="border"></div>';
$output = implode ($divider, $out_data);
echo $output;
you can use mysql_num_rows to get the number of rows you have before the while loop.
$row_count = mysql_num_rows($sql)
inside the while loop
if ($i==$row_count)
// put color $out_data[] = "<p style="colorsomething">$i {$row['news']} </p>";
else
// dont put color $out_data[] = "<p>$i {$row['news']} </p>";
does this help?
EDIT: You'd need to change the formatting for the last element of $out_data
like this:
(once the while loop completes)
…
$out_data[ count($out_data) - 1 ] = "<div style='background-color:red'>" . end($out_data) . "</div>"
$divider = '<div class="border"></div>';
$output = implode ($divider, $out_data);
echo $output;
how does that work?
精彩评论