找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1604|回复: 0
打印 上一主题 下一主题

将php数组输出html表格的方法

[复制链接]

2617

主题

2617

帖子

7789

积分

论坛元老

Rank: 8Rank: 8

积分
7789
跳转到指定楼层
楼主
发表于 2018-2-14 06:00:15 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            [U]复制代码[/U] 代码如下:
tit=array();       // strings with titles for first row
  $this->arr=array();       // data to show on cells
  $this->fons=array("#EEEEEE","#CCEEEE");  // background colors for odd and even rows
  $this->sextra="";       // extra html code for table tag
}
public function extra($s)      // add some html code for the tag table
{
  $this->sextra=$s;
}
public function background($arr) {if (is_array($arr)) $this->fons=$arr; else $this->fons=array($arr,$arr);}
public function titles($text,$style="") {$this->tit=$text; $this->sesttit=$style;}
public function addrow($a) {$this->arr[]=$a;}
public function addrows($arr) {$n=count($arr); for($i=0;$iaddrow($arr[$i]);}
public function html()
{
  $cfondos=$this->fons;
  $titulos="[tr]";
  $t=count($this->tit);
  for($k=0;$ktit[$k]);
  }
  $titulos.="[/tr]";
  $celdas="";
  $n=count($this->arr);
  for($i=0;$ifons[$i%2]);
   $linea=$this->arr[$i];
   $m=count($linea);
   for($j=0;$jsextra,$titulos,$celdas);
}
public function example()
{
  $tit=array("Apellidos","Nombre","Telefono");
  $r1=array("Garcia","Ivan","888");
  $r2=array("Marco","Alfonso","555");
  $x=new xtable();
  $x->titles($tit);      //take titles array
  $x->addrows(array($r1,$r2));   // take all rows at same time
  return $x->html();     //return html code to get/show/save it
}
}
// Example
$t1=new xtable();
echo $t1->example()."";
$t2=new xtable();
for($i=1;$iaddrow(array("ODD",$i));
  $t2->addrow(array("EVEN",$i+1));
}
$t2->background(array("pink","gold"));
$t2->titles(array("TYPE","#"));
$t2->extra(" style='width:500px; background-color:cyan; color:navy;'");
echo $t2->html()."";
$t3=new xtable();
for($i=1;$iaddrow(array("5x".$i,5*$i));
}
$t3->background(array("olive","maroon"));
$t3->titles(array("Multiplication table","5"));
$t3->extra("style='border:dotted red 10px; padding-left:4px;padding-right:4px; text-align:right;width:500px; background-color:black; color:white;'");
echo $t3->html()."";
$t4=new xtable();
$a=array("#");
for($i=1;$iaddrow($a);
$t4->background(array("pink","gold"));
$tit=array(); $tit[]="Numbers";
for($i=1;$ititles($tit);
$t4->extra("style='border:solid 1px silver; padding-left:4px;padding-right:4px; text-align:center;width:500px; background-color:cyan; color:navy;'");
echo $t4->html()."";
?>
            
            
您可能感兴趣的文章:
  • PHP通用分页类page.php[仿google分页]
  • php 分页原理详解
  • PHP分页函数代码(简单实用型)
  • php输出表格的实现代码(修正版)
  • php动态实现表格跨行跨列实现代码
  • PHP处理excel cvs表格的方法实例介绍
  • PHP 简易输出CSV表格文件的方法详解
  • php实现的漂亮分页方法
  • php将HTML表格每行每列转为数组实现采集表格数据的方法
  • PHP处理CSV表格文件的常用操作方法总结
  • php实现的后台表格分页功能示例
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端