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)!