•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,649 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 2,869 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: 980 | Replies: 2
![]() |
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?
•
•
Join Date: Oct 2007
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
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:
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 5:19 pm.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Mysql match and return words in field w/ all rows (MySQL)
- Event Handler in dynamic table rows (JavaScript / DHTML / AJAX)
- Query multiple tables with duplicate data (MySQL)
- plz help a table formatting problem (HTML and CSS)
- MySQL SELECT rows In a Date Range (MySQL)
- I lack focus... (Java)
- Mysql num rows(): Invalid argument (PHP)
- Do uncompression of disk drives affects my Database? (MS SQL)
- Changing class name in onMouseOver (HTML and CSS)
Other Threads in the PHP Forum
- Previous Thread: Problem with inserting data into mysql with PHP
- Next Thread: Newbie Needs Form Help


Linear Mode