I am trying to show results that I get from a SQL table, it is this:
what I want to do is show results 3 by 3, like this:
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; one table for each different "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:
SELECT p_name, p_lastname, assigned_bank FROM your_table order by
assigned_bank asc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.