SQL Table tbl_meals
+-----+---------+---------+---------+---------+----------+
| id | receiver| bfast | lunch | dinner | date |
+-----+---------+---------+---------+---------+----------+
| 1 | smith | served | | served | 04-18-23 |
+-----+---------+---------+---------+---------+----------+
| 2 | philip | | served | served | 04-18-23 |
+-----+---------+---------+---------+---------+----------+
| 3 | mercede | served | | served | 04-19-23 |
+-----+---------+---------+---------+---------+----------+
| 4 | annie | | served | served | 04-20-23 |
+-----+---------+---------+---------+---------+----------+
Supposing that a connection
to the database
week_meal
is successful.
I need to display this in the HTML table
.
The table should look like…
+---------+----------+----------+----------+
| Date | April 18 | April 19 | April 20 | and so on, until the last tbl_meals of each week
+---------+----------+----------+----------+
|Breakfast| 1 | 1 | None |
+---------+----------+----------+----------+
| Lunch | 1 | None | 1 |
+---------+----------+----------+----------+
| Dinner | 2 | 1 | 1 |
+---------+----------+----------+----------+
I know it is quite complicated for me as a newbie in php
, mysqli
I did only simple $query
to display DISTINCT
value from tbl_meals
date
column. It works fine only for the date which is
$sql = "SELECT DISTINCT date
FROM tbl_meals
ORDER BY date ASC";
$res = mysqli_query($connection, $sql);
But not the way it should be displayed.
+---------+----------+----------+----------+
| Date | April 18 | April 19 | April 20 | and so on, until the last tbl_meals of each week
+---------+----------+----------+----------+
|Breakfast| 1 | 1 | None |
+---------+----------+----------+----------+
| Lunch | 1 | None | 1 |
+---------+----------+----------+----------+
| Dinner | 2 | 1 | 1 |
+---------+----------+----------+----------+
2
Answers
I have solved it myself. I will be sharing it here. Thank you for the interest in helping me solve this. I appreciate your efforts.