Home > Backend Development > PHP Tutorial > 数据显示处理,该怎么处理

数据显示处理,该怎么处理

WBOY
Release: 2016-06-13 10:06:32
Original
1102 people have browsed it

数据显示处理

XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->时间段            机种            数量        2012-02-08 08    ETC56-542N    432012-02-08 09    ETC56-542N    372012-02-08 10    ETC54-623N    162012-02-08 10    ETC54-628N    22                
Copy after login


如何处理能变成以下格式?
XML code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->时间段            ETC56-542N      ETC54-623N     ETC54-628N    数量合计                08:00:00-09:00:00    43                    4309:00:00-10:00:00    37                    3710:00:00-11:00:00            16          22        38
Copy after login

sql查询语句:
SQL code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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 
Copy after login




------解决方案--------------------
是的,这种情况是交叉表。你可以搜索“交叉表”得到交叉表的定义和算法
当与数据库结合时,有现成的存储过程可以利用。不过算法的技巧性较高,您未必能看得懂

只用 php 实现时,思路很简单:
1、将查询结果保存于数组
2、加工数据到需要的格式
3、对数组做行列转换
4、遍历数组,输出
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template