html and code
|alternate row colors
| see demonstration of alternate row colorsthis will output a table with alternating row backround colors.
with this the user can read the entries much easier
full source of alternate row colors [ line 1 - 32 ] | download alternate row colors
| 1 | <?php |
| 2 | // just some random data in an array |
| 3 | $data = array('this','is','just','an','example','to','show','the','alternating','row','colors'); |
| 4 | // the two colors to switch between |
| 5 | $rowcolor1 = '#F0F0F2'; |
| 6 | $rowcolor2 = '#FFFFFF'; |
| 7 | // the background colors on mouseover |
| 8 | $hovercolor1 = '#BAD4EB'; |
| 9 | $hovercolor2 = '#DCE9F4'; |
| 10 | echo ' |
| 11 | <table style="caption-side:top; border-collapse:collapse"> |
| 12 | <caption>Demonstration</caption>'; |
| 13 | for ($n = 0; $n < count($data); $n++) |
| 14 | { |
| 15 | // this is where the magic happens |
| 16 | if($n % 2 == 1) |
| 17 | { |
| 18 | // add more things to swop with each cycle |
| 19 | $style = $rowcolor1; |
| 20 | $hoverstyle = $hovercolor1; |
| 21 | }else{ |
| 22 | $style = $rowcolor2; |
| 23 | $hoverstyle = $hovercolor2; |
| 24 | } |
| 25 | echo ' |
| 26 | <tr id="row'.$n.'" style="background:'.$style.';" onmouseover="this.style.background=''.$hoverstyle.''" onmouseout="this.style.background=''.$style.''"> |
| 27 | <td>'.$data[$n].'</td> |
| 28 | </tr>'; |
| 29 | } |
| 30 | echo ' |
| 31 | </table>'; |
| 32 | ?> |
37 hits by 13 users in the last 30 minutes.