How can you list messages for a specific user in a PHP application?

To list messages for a specific user in a PHP application, you would typically need to query a database table that stores messages, filter the messages based on the user's ID, and then display the messages on the user interface.

// Assuming $userId contains the ID of the specific user
// Connect to the database
$connection = new mysqli("localhost", "username", "password", "database");

// Check connection
if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}

// Query messages for the specific user
$query = "SELECT * FROM messages WHERE user_id = $userId";
$result = $connection->query($query);

// Display messages
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Message: " . $row["message_content"] . "<br>";
    }
} else {
    echo "No messages found for this user.";
}

// Close the connection
$connection->close();