| | |
Displaying Mysql rows, alternate colors?
![]() |
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:
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:
PHP Syntax (Toggle Plain Text)
$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.
![]() |
Similar Threads
- MySQL SELECT rows In a Date Range (MySQL)
- 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)
- 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
Views: 2373 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for PHP
access ajax apache api archive array auto box buttons cakephp cart check checkbox class classes cms code combobox css curl database date development directory display download dropdown drupal dynamic echo email error file files form forms functions header href htaccess html image include insert integration ip java javascript joomla jquery limit link list login lookup loop mail menu methods mlm mod_rewrite multiple mysql onclick order parse password paypal php problem query radio recursion regex remote rows script search select server session sort source sql string structure syntax table update upload url user validate validation variable video web website wordpress xml





