Published in: PHP
<?php $host="localhost"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="test_mysql"; // Table name // Connect to server and select databse $sql="SELECT * FROM $tbl_name"; // Define $color=1 $color="1"; echo '<table width="400" border="1" align="center" cellpadding="2" cellspacing="0">'; // If $color==1 table row color = #FFC600 if($color==1){ echo "<tr bgcolor='#FFC600'> <td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td> </tr>"; // Set $color==2, for switching to other color $color="2"; } // When $color not equal 1, use this table row color else { echo "<tr bgcolor='#C6FF00'> <td>".$rows['id']."</td><td>".$rows['name']."</td><td>".$rows['email']."</td> </tr>"; // Set $color back to 1 $color="1"; } } echo '</table>'; ?>
Comments
Subscribe to comments
You need to login to post a comment.

Keep it simple!
$color = '#FFC600'; while($rows=mysqlfetcharray($result)){ $color = $color == '#FFC600'? '#C6FF00':'#FFC600';
echo " ".$rows['id']."".$rows['name']."".$rows['email']." ";
}