Using PHP, how to efficiently make data into an HTML table?

Source: Internet
Author: User

There is a data table with the following columns

SHOP_ID Store Number
Saledate Sales Date
Trans_amt Sales Amount

Examples of data are:

1 2015-06-01 3000
2 2015-06-01 5000
3 2015-06-01 6000
1 2015-06-02 3500
2 2015-06-02 5100
3 2015-06-02 6300
...
Data is a daily record of every store, not repeat

The data in this table is displayed as one of the following tables

shop_id 2015-06-01 2015-06-02 ...
1 3000 3500 ...
2 5000 5100 ...
3 6000 6300 ...
... ... ... ...

Can think of the stupid way is to take the data out, the cycle of conditional judgment and then output into a table, you have a good solution or ideas can be efficient construction of similar forms?

Reply content:

What if there's more data? Is there a limit?
Why not get a temporary table that generates a table of data in a single day ~
Exactly the same as the data structure of the HTML table ~
So direct a select to get the loop also without the addition of conditions, maintenance, even after the table needs changed.
Big deal temporary table abandoned just fine ~

Your implementation is feasible, but the code may not look so elegant.
Suggest that you can choose some PHP framework, the main framework of the mainstream implementation of the HTML template features, the recommended use of Laravel http://laravel.com syntax is elegant! and the official version of LTS has been introduced. (Long-term support-long-time supports)

This is too easy, CodeIgniter bring the table_helper can be achieved ah, or directly traverse TR on the line.

$table = [];foreach ($result as $k = = $v) {    Array_push (sprintf ('%s%s%s ',        $v->shop_id, $v->saledate, $v- >trans_amt,//...    ));} $echo '. Implode (', $table). ';

The table is used only once, using your present method, if used multiple times, it is recommended to encapsulate

Use the MySQL limit for pagination display.

The above is the use of PHP, how to efficiently make the data into an HTML table? For more information, please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.