Data display processing, how to deal with

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.