我用了这个类: http://topic.csdn.net/u/20100803/10/24c88a46-4bc9-47bc-ba5b-b27903829627.html但是提示错误: Catchable fatal error: Argument 1 passed to Pivot::__construct() must be an array, none given请问是什么原因?部分代码: $sql = "SELECT DATE_FORMAT(`date`,'%Y-%m-%d %H') as time,type,count(*) as count FROM `barcode_2d` WHERE date >= '".$thisday2." 08:00:00' AND date < '".$thisday." 08:00:00' GROUP BY type , time ORDER BY date ASC"; $result = mysql_query($sql); $counts = array(); while($rows = mysql_fetch_array($result,MYSQL_ASSOC)) { $counts[] = $rows; } ......类代码 $p = new Pivot; $p->parse ($counts,'type','time','count'); echo $p->RenderToTable();
当与数据库结合时,有现成的存储过程可以利用。不过算法的技巧性较高,您未必能看得懂只用 php 实现时,思路很简单:
1、将查询结果保存于数组
2、加工数据到需要的格式
3、对数组做行列转换
4、遍历数组,输出
http://topic.csdn.net/u/20100803/10/24c88a46-4bc9-47bc-ba5b-b27903829627.html但是提示错误:
Catchable fatal error: Argument 1 passed to Pivot::__construct() must be an array, none given请问是什么原因?部分代码:
$sql = "SELECT DATE_FORMAT(`date`,'%Y-%m-%d %H') as time,type,count(*) as count FROM `barcode_2d` WHERE date >= '".$thisday2." 08:00:00' AND date < '".$thisday." 08:00:00' GROUP BY type , time ORDER BY date ASC";
$result = mysql_query($sql);
$counts = array();
while($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
$counts[] = $rows;
}
......类代码
$p = new Pivot;
$p->parse ($counts,'type','time','count');
echo $p->RenderToTable();
$p = new Pivot ( $counts, 'type', 'time', 'count' );
echo $p->RenderToTable ();
就可以。