Obarveni parity ve vypisech
authorThomas Mudrunka <tomas@mudrunka.cz>
Tue, 22 Nov 2011 17:13:07 +0000 (18:13 +0100)
committerThomas Mudrunka <tomas@mudrunka.cz>
Tue, 22 Nov 2011 17:13:07 +0000 (18:13 +0100)
index.php

index 110efbe8a9b263f7566968ca94fc2b5ea4643b69..8ee47b8b099b87bbe4d00ac747fe51a29bb6c7a1 100755 (executable)
--- a/index.php
+++ b/index.php
@@ -34,10 +34,11 @@ require_once('Barcode.class.php');
 * @author   Tomas Mudrunka
 */
 class HTML {
-       function row($row,$type=false) {
+       function row($row,$type=false,$class=false) {
                $html = '';
+               $class = $class ? $class=" class='$class' " : '';
                if($type) $html.="<$type>";
-               $html.='<tr>';
+               $html.="<tr$class>";
                $td = $type == 'thead' ? 'th' : 'td';
                foreach($row as $var) {
                        if(trim($var) == '') $var = '&nbsp;';
@@ -48,15 +49,18 @@ class HTML {
                return $html;
        }
 
-       function table(&$table, $params='border=1') {
+       function table(&$table, $parity_class=array('tr_odd','tr_even'), $params='border=1') {
                $html="<table $params>";
                $header=true;
+               $even=false;
                foreach($table as $row) {
                        if($header) {
                                $html.=$this->row(array_keys($row),'thead');
                                $header=false;
                        }
-                       $html.=$this->row($row);
+                       $class = $parity_class ? $parity_class[$even] : false;
+                       $html.=$this->row($row,false,$class);
+                       $even = !$even;
                }
                $html.='</table>';
                return $html;
@@ -181,6 +185,7 @@ td,body { background-color: white; }
 table { background-color: orange; border: orange; }
 a, a img { text-decoration:none; color: darkblue; border:none; }
 li a, a:hover { text-decoration:underline; }
+.tr_even td { background-color: lemonchiffon; }
 
 .menu li {
        float: left;
This page took 0.130707 seconds and 4 git commands to generate.