php - Sort all new messages according to the date when message has been received by the users

one text

I want to sort all the messages on top that has been received by the users according to the date when the message has been sent to the users

here is the code:

<?php
if ($_SESSION['role_as'] === '1') {
    $query = "SELECT u.fname, u.lname, u.unique_id, shop.name as shopname 
              FROM user u
                join tattooshops shop on shop.id = u.shopid 
              WHERE unique_id= '".$_SESSION['unique_id']."' ";
} else {
    $query = "SELECT fname, lname, unique_id 
                FROM user 
                WHERE unique_id= '".$_SESSION['unique_id']."' ";
}

$query_run = mysqli_query($con, $query);
$check_user = mysqli_num_rows($query_run) > 0;

if ($check_user) {
    while ($row = mysqli_fetch_array($query_run)) {
        if ($_SESSION['role_as'] === '1') {
            $userName = $row['shopname'];
        } else {
            $userName = $row['fname'] ." ". $row['lname'];
        }
        echo '<div class="details">';
        echo '<span>' . "Messages for " . $userName .'</span>';
        echo '</div>';
    }
}
?>

this is the image that the message is not arranged accordingly: enter image description here

I'll expect that all the messages who are currently receiving according to date will sort on top

Source