User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,573 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,583 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1240 | Replies: 2
Reply
Join Date: May 2005
Posts: 229
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Displaying Mysql rows, alternate colors?

  #1  
Oct 29th, 2007
Hey, I'm using a while loop to display all the rows of a table in my database, and wondered if anyone knows how I can make it so the background color of each row alternates between two different colors. I'm using php to call the information, so I can stick some HTML in there if needed, but is this possible?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Posts: 4
Reputation: Rankenian is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Rankenian Rankenian is offline Offline
Newbie Poster

Re: Displaying Mysql rows, alternate colors?

  #2  
Oct 29th, 2007
It can be done, just store the colour you want in a variable and swap it with a 2nd colour every time you go around the loop

Something like this:

$bg = '#FF0000';
while ($row = mysql_fetch_array($result)) {
  if ($bg == '#FF0000') $bg = 'FFFF00';
  else $bg = '#FF0000';
 $output .= "<tr bgcolor=\"#" . $bg . "\">" . "<td>" . $row['data'] . "</td></tr>"
}
echo $output;
Last edited by Rankenian : Oct 29th, 2007 at 6:19 pm.
Reply With Quote  
Join Date: May 2005
Posts: 229
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: Displaying Mysql rows, alternate colors?

  #3  
Oct 29th, 2007
Thanks, that worked great!
Last edited by nathanpacker : Oct 29th, 2007 at 6:44 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC