404_3@
PHP@H_
404_3@class xtable@H_
404_3@{@H_
404_3@private $tit,$arr,$fons,$sextra;@H_
404_3@public function __construct()@H_
404_3@{@H_
404_3@$this->tit=array();// strings with titles for first row @H_
404_3@$this->arr=array();// data to show on cells@H_
404_3@$this->fons=array("#EEEEEE","#CCEEEE");// background colors for odd and even rows@H_
404_3@$this->sextra="";// extra html code for table tag@H_
404_3@}public function extra($s)// add some html code for the tag table@H_
404_3@{@H_
404_3@$this->sextra=$s;@H_
404_3@}@H_
404_3@public function background($arr) {if (is_array($arr)) $this->fons=$arr; else $this->fons=array($arr,$arr);}@H_
404_3@public function titles($text,$style="") {$this->tit=$text; $this->sesttit=$style;}@H_
404_3@public function addrow($a) {$this->arr[]=$a;}@H_
404_3@public function addrows($arr) {$n=count($arr); for($i=0;$i<$n;$i++) $this->addrow($arr[$i]);}@H_
404_3@public function html()@H_
404_3@{@H_
404_3@$cfondos=$this->fons;@H_
404_3@$titulos="
404_3@$t=count($this->tit);@H_404_3@for($k=0;$k<$t;$k++)@H_404_3@{@H_404_3@$titulos.=sprintf("%s | ",$this->tit[$k]);@H_404_3@}@H_404_3@$titulos.="
404_3@$n=count($this->arr);@H_
404_3@for($i=0;$i<$n;$i++)@H_
404_3@{@H_
404_3@$celdas.=sprintf("
",$this->fons[$i%2]);@H_404_3@$linea=$this->arr[$i];@H_404_3@$m=count($linea);@H_404_3@for($j=0;$j<$m;$j++)@H_404_3@$celdas.=sprintf("%s | 404_3@$celdas.="
404_3@}@H_
404_3@return sprintf("
sextra,$titulos,$celdas);@H_
404_3@}@H_
404_3@public function example()@H_
404_3@{@H_
404_3@$tit=array("Apellidos","Nombre","Telefono"); @H_
404_3@$r1=array("Garcia","Ivan","888"); @H_
404_3@$r2=array("Marco","Alfonso","555"); @H_
404_3@$x=new xtable(); @H_
404_3@$x->titles($tit); //take titles array@H_
404_3@$x->addrows(array($r1,$r2)); // take all rows at same time@H_
404_3@return $x->html();//return html code to get/show/save it @H_
404_3@}@H_
404_3@}
@H_404_3@// Example@H_404_3@$t1=new xtable();@H_404_3@echo $t1->example()."
";
$t2=new xtable();@H_404_3@for($i=1;$i<=10;$i+=2)@H_404_3@{@H_404_3@$t2->addrow(array("ODD",$i));@H_404_3@$t2->addrow(array("EVEN",$i+1));@H_404_3@}@H_404_3@$t2->background(array("pink","gold"));@H_404_3@$t2->titles(array("TYPE","#"));@H_404_3@$t2->extra(" style='width:500px; background-color:cyan; color:navy;'");@H_404_3@echo $t2->html()."
";
$t3=new xtable();@H_404_3@for($i=1;$i<=6;$i++)@H_404_3@{@H_404_3@$t3->addrow(array("5x".$i,5*$i));}@H_404_3@$t3->background(array("olive","maroon"));@H_404_3@$t3->titles(array("Multiplication table","5"));@H_404_3@$t3->extra("style='border:dotted red 10px; padding-left:4px;padding-right:4px; text-align:right;width:500px; background-color:black; color:white;'");@H_404_3@echo $t3->html()."
";
$t4=new xtable();@H_404_3@$a=array("#");@H_404_3@for($i=1;$i<=10;$i++)@H_404_3@{@H_404_3@$a[]=$i;@H_404_3@}@H_404_3@$t4->addrow($a);@H_404_3@$t4->background(array("pink","gold"));@H_404_3@$tit=array(); $tit[]="Numbers";@H_404_3@for($i=1;$i<=10;$i++) $tit[]="#";@H_404_3@$t4->titles($tit);@H_404_3@$t4->extra("style='border:solid 1px silver; padding-left:4px;padding-right:4px; text-align:center;width:500px; background-color:cyan; color:navy;'");@H_404_3@echo $t4->html()."
";@H_
404_3@?>@H_
404_3@