I’ve got a query that gives me something like the following result when I would print out a table:
+---------------------------------------------------------------------+
| ID | Name | Color | Size | Qty |
+---------------------------------------------------------------------+
| 1 | First | Green | S | 1 |
| 2 | First | Green | L | 2 |
| 3 | First | Green | XL | 1 |
| 4 | First | Red | M | 2 |
| 5 | First | Red | L | 3 |
| 6 | Second | Blue | S | 1 |
| 7 | Second | Blue | M | 4 |
+---------------------------------------------------------------------+
Now I want to make an overview (in real life these are products) where someone can click a button to edit or delete. I want to loop over it with a foreach loop or something and print it out something like this:
+========================================================================+
| Name | Color | Size | Qty | Action |
+========================================================================+
| First | Green | S | 1 | Edit|Delete |
| | | L | 2 | Edit|Delete |
| | | XL | 1 | Edit|Delete |
+------------------------------------------------------------------------+
| First | Red | M | 2 | Edit|Delete |
| | | L | 3 | Edit|Delete |
+------------------------------------------------------------------------+
| Second | Blue | S | 1 | Edit|Delete |
| | | M | 4 | Edit|Delete |
+------------------------------------------------------------------------+
but somehow I just can’t get my head around how I would program this loop. Or should I change the query?
I hope someone can help. If you need more information, please tell me.
You could do some of this in the database which could well make it easier to display the data in your code:
The result would look like this:
Now in your code, this makes it much easier to output the way you would like it to.