How to Have Alternating Colors in Table Row Results
1. Pick two colors for table cell backgrounds. For example, light cream and light green.
2. When you dip into the MySQL table, you will be using a while loop. You will also be using two other elements.
3. The first is the use of $i=0, $i++ while using the “while loop”
4. The second is the use of the modulo % to get the remainder.
5. As you use the “while” loop, you increment the $i by 1 each time, and you will be dividing $i by 2, $i % 2.
6. You also place the condition, if the remainder is 0, then use the light cream, and if the remainder is 1, then use the light green.
Note, if you want three colors, just do the same thing, use $i % 3, and if the remainder is 0, 1 or 2, then use color1, color2 or color3. Obviously, if your site is gay, and you want the gay colors to appear, use $i % 6, assigning 6 colors, but I think that would look tacky. I think red and white with a little blue and some stars appearing in the background would look like an American flag.
Val Zubiri
Programming by Val Zubiri
Art by Val Zubiri
Arts Global Impact.org / Original Art and Art Books for Collectors for sale
Chicago Art Movement.com
Get a Massage Contact and Shop using your mobile phone
This post has 20 feedbacks awaiting moderation...
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| << < | > >> | |||||
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | ||
Tips on the use of PHP and MySQL for your website. If you need help with your site, ask and I'll see if I can help. If you need long-term help with your website, let me know as well.