How can a custom text message be displayed when no results are found in a MySQL query in PHP?

If no results are found in a MySQL query in PHP, you can display a custom text message by checking the number of rows returned by the query. If the number of rows is zero, you can echo out the custom message.

// Execute the MySQL query
$result = mysqli_query($conn, "SELECT * FROM table WHERE condition");

// Check if any results are found
if(mysqli_num_rows($result) == 0) {
    echo "No results found.";
} else {
    // Process the results
    while($row = mysqli_fetch_assoc($result)) {
        // Display or use the results
    }
}