Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Alternate Row Colours

Code Wizard, 12-30-2006

A script to alternate row colours when getting information from a MySQL database.

<?

// Header rows
print ("<body bgcolor=black text=white>");
print ("<table border=1 width=100%>
<tr>
<td width=18%><font face=Verdana, Arial, Helvetica, sans-serif size=2><b>Name</b></font></td>
<td width=82%><font face=Verdana, Arial, Helvetica, sans-serif
size=2><b>Email</b></font></td>");

// DB connection information
$connection = mysql_connect("localhost","username","password");
$db = mysql_select_db("database", $connection);

// SQL Query
$sql = mysql_query("SELECT * FROM table");

$alternate = "2"; // number of alternating rows
while ($row = mysql_fetch_array($sql)) {
$name = $row["name"]; //name of field
$email = $row["email"];

if ($alternate == "1") {
$colour = "#000000";
$alternate = "2";
}

else {
$colour = "#464646";
$alternate = "1";
}

print ("</tr><tr><td bgcolor=$colour width=18%><font face=Verdana, Arial, Helvetica,
sans-serif size=2>$name</font></td><td bgcolor=$colour width=82%>
<font face=Verdana, Arial, Helvetica, sans-serif size=2>$email</font></td>
</tr>");
}
print ("</table>");

?>
Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions