Php Programming Code Examples
Php > Look and Feel Code Examples
Another Alternate Row color
Another Alternate Row color
<?php
// Displays alternate table row colors
function row_color($i){
$bg1 = "#0099FF"; // color one
$bg2 = "#336699"; // color two
if ( $i%2 ) {
return $bg1;
} else {
return $bg2;
}
}
//DB connection
$connection = mysql_connect("localhost","userName","password");
$db = mysql_select_db("databaseName");
$sql = "select * from tableName"; // Database Query
$result = mysql_query("$sql"); // Database Query result
// Starts the table
echo "<table bgcolor=#FFFFFF border=0 cellpadding=1 cellspacing=1>\n";
// Create the contents of the table.
for( $i = 0; $i < $row = mysql_fetch_array($result); $i++){
echo "<TR>\n"
."<TD bgcolor=".row_color($i).">".$row["fname"]."</TD>\n"
."<TD bgcolor=".row_color($i).">".$row["lname"]."</TD>\n"
."</TR>";
}
echo "</TABLE>"
?>