making every other line a different colour

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

making every other line a different colour

Post by aceconcepts »

hi,

If i extract a list of data from a database how can I make every other row a different colour.

Here is an example of how I'd like it to look: http://unstats.un.org/unsd/methods/m49/ ... a.htm#ftna

Thanks
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post by blackbeard »

After you extract the data, use a for loop to echo out each row. Inside the loop, test for odd/even, and set the background color for the row as needed.
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

In your CSS sheet you could have two different ID's for the different background color rows. When you are looping through your results, alternate the tags when filling in the table.

Wayne
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

What you are looking for is commonly refered to as zebra striping or alternating row colors. There have been thousands of posts (maybe hundreds, but I think thousands sums it up best) about this topic in this community. Search around a little. You'll find them.
Post Reply