Good day fellow warrior programmers, Time for another simple PHP hack. This time, instead of explaining a function and how to use, I will give you a simple, one liner for alternating colors in table rows.
PHP Quicky - Alternate table row colors
5
Good day fellow warrior programmers,
Time for another simple PHP hack. This time, instead of explaining a function and how to use, I will give you a simple, one liner for alternating colors in table rows.
You see this often in tables with lots of data, rows alternate color (white/grey for example). Designers do this to make it easy for the eye to follow a row. It's a quick visual guide for accuracy.
so without further ado, here's the code:
basically, $clrCOunter is incremented after each pass, hence we check the remainder of the counter divided by 2. Every second pass will return a reminder of 0, therefore alternating colors.
Enjoy!
WebPro
Time for another simple PHP hack. This time, instead of explaining a function and how to use, I will give you a simple, one liner for alternating colors in table rows.
You see this often in tables with lots of data, rows alternate color (white/grey for example). Designers do this to make it easy for the eye to follow a row. It's a quick visual guide for accuracy.
so without further ado, here's the code:
Code:
<tr bgcolor="<?php echo ($clrCounter++ % 2 == 0 ? 'color1' : 'color2'); ?>"> color 1, color 2 should be HEX codes (ie. #ffffff, #ff0000)
Enjoy!
WebPro
- jminkler
Next Topics on Trending Feed
-
5