How to efficiently construct an html table using php?

Source: Internet
Author: User
There is a data table with the following shop_id store number saledate sales date trans_amt sales amount data example: 12015-06-01300022015-06-01500032015-06-01600012015-06-02350022015-06-02510032015-06-02... there is a data table with the following columns

Shop_id store ID
Saledate sales date
Trans_amt sales amount

Data example:

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 record of each store every day, not repeated

The data in this table is shown as follows:
Shop_id 2015-06-01 2015-06-02 ...
1 3000 3500 ...
2 5000 5100 ...
3 6000 6300 ...
... ... ... ...

The stupid way to think of it is to extract the data, cyclically add conditions to judge and output the data to a table. Do you have any good solutions or ideas to efficiently construct similar tables?

Reply content:

What if there is more data? Is there a limit?
Why not create a temporary table and generate a data table every day ~
The data structure of the html table is exactly the same ~
In this way, a select statement can be used directly ~ You do not need to add conditions to the cycle, or maintain them, even if the table requirements change in the future.
Big deal, temporary tables are discarded ~

Your implementation method is feasible, but the Code may not seem so elegant.
We recommend that you use some PHP frameworks. The mainstream frameworks basically implement the html template function. We recommend that you useLaravelHttp://laravel.com syntax is very elegant! In addition, the LTS version has been officially released. (Long-term support-long-time support)

This is too easy. The table_helper provided by Codeigniter can be implemented, or you can just traverse tr directly.

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

If the table is used only once, you can use the current method. If it is used multiple times, it is recommended to encapsulate

Use Mysql Limit for paging display

The above is how to efficiently construct an html table using php? For more information, see the PHP Chinese website (www.php1.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.