Data display processing
XML Code
Time period number of machines 2012-02-08 etc56-542n 432012-02-08 etc56-542n 372012-02-08 etc54-623n 162012-02-08 etc54-628n 22
What can I do to change to the following format?
XML Code
Time period etc56-542n etc54-623n etc54-628n Quantity total 08:00:00-09:00:00 4309:00:00-10:00:00 Notoginseng 3710:00:00-11:00:00 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 >= ' ". $thisday 2." 08:00:00 ' and Date < '. $thisday. " 08:00:00 ' GROUP by type, time ORDER by date ASC
------Solution--------------------
Yes, this is a cross-table. You can search for "crosstab" to get a cross-table definition and algorithm
When combined with a database, there are ready-made stored procedures to take advantage of. However, the technique of the algorithm is high, you may not be able to read
When implemented in PHP only, the idea is simple:
1. Save the query results in an array
2, processing data to the required format
3, the array to do row and column conversion
4. Iterate through the array, output