$dbc = mysql_connect('localhost','root','') or die (mysql_error());
mysql_select_db('payroll') or die (mysql_error());
$sql = "SELECT * FROM employee ORDER BY employee_id DESC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
echo "
".$row['first_name']." ".$row['last_name']."
";
}
I wanted to add an alternating color in the loop. what code should I add?
Answer
$rowCount = 0;
$colorOne = '#ffffff';
$colorTwo = '#f3f3f3';
while($row = mysql_fetch_array($result)){
$rowColor = ($rowCount % 2) ? $colorOne : $colorTwo;
echo " ";
$rowCount++;
}
Edited after @Jayrox comment.
No comments:
Post a Comment