How can you display the text "No Data" when there are no entries in the MySQL database?

To display the text "No Data" when there are no entries in the MySQL database, you can first check if there are any rows returned from the database query. If there are no rows, you can display the text "No Data" instead of looping through the results. This can be achieved by using the mysqli_num_rows() function to check the number of rows returned by the query.

// Connect to MySQL database
$conn = mysqli_connect("localhost", "username", "password", "database");

// Query to retrieve data from the database
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);

// Check if there are any rows returned
if(mysqli_num_rows($result) == 0) {
    echo "No Data";
} else {
    // Loop through the results and display them
    while($row = mysqli_fetch_assoc($result)) {
        echo $row['column_name'] . "<br>";
    }
}

// Close the database connection
mysqli_close($conn);