< /p>
As shown in the figure, how to make the same numbers in order_id only be output once in a loop
The business is like this. This table records the relationship between an order and a product. order_id is the order id.
Therefore, the two 815s recorded in the table indicate that they are the same order. They have the same order id
Then the question is how to merge the same order_id into one output when displaying the order list
The above picture shows the separate output of the same order_id and how to merge them
Output the array according to the order ID, and directly merge the same ones (please tell me if there is anything wrong)
This has nothing to do with your foreach loop and everything to do with the logic of rendering the page.
For example: when you find that there is already the same order number before, it will be ok if you no longer display the order number
There is a problem with the table structure. Generally, there is an order table and an order product table. For your current table structure, you can first query group by order_id and then foreach order_id and then loop to query all the products in this order_id
This should be the result you want, process it and then iterate.
Remove duplicates when fetching the database
select dinstinct(order_id)