How can the PHP code snippet be improved to handle the scenario where the query result is empty more effectively?

The issue with the current PHP code snippet is that it does not handle the scenario where the query result is empty effectively. To improve this, we can check if the query result is empty before trying to fetch the data. If the result is empty, we can display a message to indicate that no data was found.

// Execute the query
$result = mysqli_query($conn, "SELECT * FROM users WHERE id = 123");

// Check if the query result is not empty
if(mysqli_num_rows($result) > 0) {
    // Fetch the data
    $row = mysqli_fetch_assoc($result);
    // Display the user's name
    echo "User's name: " . $row['name'];
} else {
    // Display a message if no data was found
    echo "No user found with the specified ID.";
}