the latest
October 20, 2008 New Backup Script has been launched. Some house keeping has been done around the site and we have a few new items to be added soon.

the greatest

» Backup Script
» Contact Script
» PHP Includes
» Image Gallery

Alternating Colors Tutorial

Description

This tutorial will show you how to display alternating colors in your SQL results.

Tutorial

This is great when you are grabbing a bunch of information and showing it in a table, really makes the results professional.

Here is a an easy example:

<?

include "yourdatabaseinfo.php";

mysql_connect("$host","$user","$pass");
mysql_select_db("$database");

$result = mysql_query("select * from somedatabase");
$number = mysql_num_rows($result);

echo "<table>";

//set the 2 colors you want to use
$color1 = "#ffffff";
$color2 = "#aaaaaa";

//set the row count to zero (you have to start somewhere)
$row_count = 0;

while($r=mysql_fetch_array($result))
{
$info=$r["info"];

//This determines what color to display
$row_color = ($row_count % 2) ? $color1 : $color2;

//Here you are specifing row_color (one of the 2 colors you chose above)
echo "<tr><td bgcolor=$row_color>$info</td></tr>";

//this adds one to the row count.
$row_count++;
}
echo"</table>";
?>



Use it well!


Home : Services : Scripts : Tutorials : Hosting : Contact