How to sort user data by id

As I told in comments you can use a nested while loop for this

Updated

while ($data = mysqli_fetch_array($c_result)) {
    $messages[] = $data["msg_body"];
    $user_from = $data["user_from"];
    if($user_from==38){
        $d_query = "SELECT * FROM register WHERE id='$user_from'";
        $d_result = mysqli_query($conn,$d_query);
        while ($fdata = mysqli_fetch_assoc($d_result)) {
            $frname = $fdata["firstname"];


        }

    } //This is end of if
        echo "$frname sent you a message <br> $messages[]";
}//This END of First while loop

I have wrote what I have understood. Hope it helps you

Leave a Comment