How can a PHP beginner properly structure an IF-Abfrage in connection with a MySQL-SELECT statement?

When structuring an IF-Abfrage (IF statement) in connection with a MySQL-SELECT statement in PHP, you need to first execute the SELECT query and then use an IF statement to check if the query returned any results. You can achieve this by fetching the data from the query result and then checking if there are any rows returned. If there are rows, you can proceed with processing the data, otherwise, you can handle the case where no results are found.

// Execute the MySQL SELECT query
$query = "SELECT * FROM your_table WHERE your_condition";
$result = mysqli_query($connection, $query);

// Check if the query returned any results
if(mysqli_num_rows($result) > 0) {
    // Fetch the data from the query result and process it
    while($row = mysqli_fetch_assoc($result)) {
        // Process the data here
    }
} else {
    // Handle the case where no results are found
    echo "No results found.";
}

// Don't forget to free the result set
mysqli_free_result($result);