I have a webpage for messaging purposes. The SQL table for the webpage looks something like this:
So far, the output on my webpage is:
User 1 (2023-06-28)
Lorem ipsum dolor sit amet
User 2 (2023-06-29)
consectetur adipiscing elit
User 1 (2023-06-29)
sed do euismod tempor incididunt
User 1 (2023-06-29)
ut labore et dolore magna aliqua.
Meanwhile I want the output to be:
2023-06-28
User 1
Lorem ipsum dolor sit amet
2023-06-29
User 2
consectetur adipiscing elit
User 1
sed do euismod tempor incididunt
ut labore et dolore magna aliqua.
Basically if the message is sent on the same date I don't want to display the date twice. And if the message is sent by the same user I don't want to display the user's username twice (or thrice, or any else). How can I possibly achieve this? I'm still figuring my way around PHP and mySQL and I'm stuck right now. A help might be very lovely, to be honest @_@
Thank you very much in advance!
Edit: the PHP code looks something like this just in case. ultimately basic stuff tho lol
msg_id | msg | msg_sender | msg_date |
1 | Lorem ipsum dolor sit amet | User 1 | 2023-06-28 |
2 | consectetur adipiscing elit | User 2 | 2023-06-29 |
3 | sed do eiusmod tempor incididunt | User 1 | 2023-06-29 |
4 | ut labore et dolore magna aliqua | User 1 | 2023-06-29 |
So far, the output on my webpage is:
User 1 (2023-06-28)
Lorem ipsum dolor sit amet
User 2 (2023-06-29)
consectetur adipiscing elit
User 1 (2023-06-29)
sed do euismod tempor incididunt
User 1 (2023-06-29)
ut labore et dolore magna aliqua.
Meanwhile I want the output to be:
2023-06-28
User 1
Lorem ipsum dolor sit amet
2023-06-29
User 2
consectetur adipiscing elit
User 1
sed do euismod tempor incididunt
ut labore et dolore magna aliqua.
Basically if the message is sent on the same date I don't want to display the date twice. And if the message is sent by the same user I don't want to display the user's username twice (or thrice, or any else). How can I possibly achieve this? I'm still figuring my way around PHP and mySQL and I'm stuck right now. A help might be very lovely, to be honest @_@
Thank you very much in advance!
Edit: the PHP code looks something like this just in case. ultimately basic stuff tho lol
PHP:
<?php
include "connect.php";
$data = mysqli_query($connect, "SELECT * from `table1`");
$rows = mysqli_fetch_all($data, MYSQLI_ASSOC);
foreach ($rows as $row) {
if($row["msg_sender"] == "User 1") {
echo "<div class='msg'><div class='msgcontainer'>" . $row["msg"] . "</div><div class='msgdate'>" . $row["msg_date"] . "</div></div>";
}elseif($row["msg_sender"] == "User 2") {
echo "<div class='msg'><div class='msgcontainer'>" . $row["msg"] . "</div><div class='msgdate'>" . $row["msg_date"] . "</div></div>";
}
}
?>
Last edited: