Alternating Rows in PHP

free php tutorials, php classes, php utilities, free tools Alternating row colors is a very good way to make big tables more readable and attractive. We have used modulator operator to handle alternative row like 2%5.
<?php
$host="localhost"; // Host name.
$db_user="Your MySql User Name ";
$db_password="Your MySql Password";
$database="tutorial"; // Database name.
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);

$query="select * from tutorials";
$result=mysql_query($query);

echo "<h2>PHP Alternating Rows </h2>";
echo "<table>";
$i = 0;
while($myrows=mysql_fetch_array($result)){

if($i%2 ==0)
{
echo "<tr bgcolor='#FFFFCC'>";
$i++;
}
else
{
echo "<tr bgcolor='#FFCC00'>";
$i++;
}
print "<td><a href='#'>".$myrows['title']."</a></td>";
echo "</tr>";
}
echo "</table>";
?>

Bookmark This Page