Data Display Processing XMLcode time period number of hosts 2012-02-0808ETC56-542N432012-02-0809ETC56-542N372012-02-0810ETC54-623N16 data display processing
XML code
Time period machines quantity 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
How can this problem be solved?
XML code
Time period ETC56-542N ETC54-623N ETC54-628N quantity total 08:00:00-09:00:00 43 4309: 00: 00-10:00:00 37 3710: 00: 00-11:00:00 16 22 38
SQL query statement:
SQL code
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
------ Solution --------------------
Yes, this is a cross tabulation. You can search "cross tabulation" to get the definition and algorithm of the cross tabulation.
When combined with databases, there are ready-made stored procedures that can be used. However, you may not be able to understand the algorithm because it is highly skillful.
The idea is simple when php is used only:
1. Save the query results in an array
2. process data to the required format
3. convert rows and columns of arrays
4. traverse the array and output