so I tried to sort data from my SQL table based on username. This concept is based on the user which is connect to the website.
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Profile</title>
    <style type="text/css">
        input{
            border: none;
        }
    </style>
</head>
<body>
<table  cellspacing= 0 cellpadding=10>
        <tr>
            <td>#</td>
            <td>Expeditor</td>
            <td>Mesaj</td>                              
        </tr>
        <?php
            $i=1;
        $id2= $_SESSION["id"];
        $result= mysqli_query($conn, "SELECT * FROM tb_user WHERE id= $id2");
        $row = $result->fetch_assoc();
        $userconn = $row['username'];
        $rows= mysqli_query($conn, "SELECT * FROM mesajeuseri WHERE username='$userconn'")
                                    
        ?>
        <?php foreach ($rows as $row): ?>
        <tr>
            <td><?php echo $i++; ?></td>
            <td><?php echo $row["user"] ?></td>
            <td><?php echo $row["descriere"]; ?></td>
            <td>
                <a href="">Contact</a>
            </td>
        </tr>
        <?php endforeach; ?>    
</table>
                
</body>
</html>
As you can see I try to use an SQL statement where I use the condition username=$userconn (if I try to echo this value it show the right one). I am not sure if this can work like this. If I leave it like this there will be no result shown, like the table is empty but I have a few rows there with multiple users. This is my table:
And this is my table user:
I know this is not secure because the SQL injection and is not healthy to create my own statement but first I want to see it working as intended.


 
     
     
     
    