What are some best practices for handling conditional statements in PHP, especially when checking for the presence of data in a MySQL query result?

When handling conditional statements in PHP, especially when checking for the presence of data in a MySQL query result, it's important to use appropriate functions to accurately determine if data exists. One common method is to use functions like `mysqli_num_rows()` to check the number of rows returned by a query. This allows you to safely proceed with processing the data only if it actually exists.

// Assume $conn is a valid MySQL database connection
$query = "SELECT * FROM users WHERE id = 1";
$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) > 0) {
    // Data exists, proceed with processing
    while($row = mysqli_fetch_assoc($result)) {
        // Process each row of data
        echo $row['username'];
    }
} else {
    // No data found
    echo "No results found.";
}

mysqli_free_result($result);
mysqli_close($conn);