[英]Show table with results grouped 3 by 3
I am trying to show results that I get from a SQL table, it is this:我试图显示我从 SQL 表中得到的结果,它是这样的:
what I want to do is show results 3 by 3, like this:我想要做的是 3 x 3 显示结果,如下所示:
I mean a table for every 3 results that the "assigned_bank" field matches, and if there are 4 results with the same number in "assigned_bank", I also show it in that same table, that is;我的意思是“assigned_bank”字段匹配的每 3 个结果的表格,如果“assigned_bank”中有 4 个结果具有相同的数字,我也会在同一个表格中显示它,即; one table for each different "assigned_bank" id.
每个不同的“assigned_bank”ID 对应一张表。 I've been trying most of the day and the closest thing I've come to is this:
我一天中的大部分时间都在尝试,最接近的是:
This is my last code:这是我最后的代码:
<?php $tables = sizeof($search) / 3; for ($i = 0; $i < $tables; $i++) { ?> <table class="table customers"> <thead class="thead-blue"> <tr> <th scope="col-xs-2">Name</th> <th scope="col-xs-2">Lastname</th> <th scope="col-xs-2">Bank ID</th> </tr> </thead> <tbody> <?php foreach ($search as $item){ echo '<tr align="left">'; echo '<td class="col-xs-2">' . $item["p_name"] . '</td>' . "\\r\\n"; echo '<td class="col-xs-2">' . $item["p_lastname"] . '</td>' . "\\r\\n"; echo '<td class="col-xs-2">' . $item["assigned_bank"] . '</td>' . "\\r\\n"; echo '</tr>'; } ?> </tbody> </table> <?php echo "\\r\\n"; } ?>
Thank you very much for any possible help or comments and thank you for taking the time to respond.非常感谢您提供任何可能的帮助或意见,并感谢您花时间回复。
<?php $result = array(); foreach ($search as $key => $item) { $result[$item['assigned_bank']][$key] = $item; } foreach($result as $key=>$search_items){ echo '<table class="table customers" border="2" > <thead class="thead-blue"> <tr> <th scope="col-xs-2">Name</th> <th scope="col-xs-2">Lastname</th> <th scope="col-xs-2">Bank ID</th> </tr> </thead> <tbody>'; foreach($search_items as $skey=>$item){ echo '<tr align="left">'; echo '<td class="col-xs-2">' . $item["p_name"] . '</td>' . "\\r\\n"; echo '<td class="col-xs-2">' . $item["p_lastname"] . '</td>' . "\\r\\n"; echo '<td class="col-xs-2">' . $item["assigned_bank"] . '</td>' . "\\r\\n"; echo '</tr>'; } echo '</tbody> </table>'; } <?>
You can use order by on assigned_bank column with ascending order:您可以在assigned_bank列上按升序使用order by:
SELECT p_name, p_lastname, assigned_bank FROM your_table order by
assigned_bank asc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.