Alternating Row Color
Posted: Sun Mar 12, 2006 12:57 pm
I searched the forum and wasnt able to find anything to really help me, however, im sure this question has been asked many times.
Im trying to just pull data from a db and put it into a table, with each row having alternating colors.. its so much easier on the eyes isnt it?
. I made up some sample code that might help. It pulls all the users from a db, pulls info from there.. then goes to the animals table and selects every animal in there with that username set as its owner.. then counts them... Its a very usless script but i just want to know how it was done so i created something to work with.
Here is my code (sorry for the sloppyness):
Im trying to just pull data from a db and put it into a table, with each row having alternating colors.. its so much easier on the eyes isnt it?
Here is my code (sorry for the sloppyness):
Code: Select all
<?
include("db/db.php");
$HTTP_POST_VARS;
echo "<table width=\"700\" height=\"85\" cellpadding=\"0\" border=\"1\" cellspacing=\"0\">";
echo "<tr><td>Name(username)</td><td>fish</td><td>Dogs</td><td>Total animals</td></tr>";
$get_users= mysql_query("SELECT * FROM my_users ORDER BY name ASC");
while($rows = mysql_fetch_row($get_users))
{
while($users = mysql_fetch_assoc($get_users))
{
//now print the results:
$loginname= $users['loginname'];
$result = mysql_query("SELECT * FROM my_users WHERE loginname = \"$loginname\" ");
while($myrow = mysql_fetch_assoc($result))
{
//now print the results:
$id= $myrow['id'];
$loginname= $myrow['loginname'];
$name = $myrow['name'];
}
//get hits and view
$result = mysql_query("SELECT * FROM my_animals WHERE owner = '$loginname' AND animal = 'fish'");
$number_of_fish = mysql_num_rows($result);
$get_sub = mysql_query("SELECT * FROM my_animals WHERE owner = '$loginname' AND animal = 'dog' ");
$number_of_dogs = mysql_num_rows($get_sub);
//print results.
$total_animals = $number_of_fish+$number_of_dogs;
echo "<tr align=center ><td>". $name . "(". $loginname .") </td><td> " .$number_of_fish. "</td><td>". $number_of_dogs . " </td><td>". $total_animals ."</td></tr>";
}
};
echo "</table>";
?>