In what scenarios would using mysql_num_rows() be helpful in displaying the output of a SQL query in PHP?

When displaying the output of a SQL query in PHP, using mysql_num_rows() can be helpful in scenarios where you want to know the number of rows returned by the query. This can be useful for displaying the total count of results, pagination, or determining if any results were returned at all.

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

// Run SQL query
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);

// Get number of rows returned
$num_rows = mysqli_num_rows($result);

// Display number of rows
echo "Total rows: " . $num_rows;

// Display query results
while($row = mysqli_fetch_assoc($result)) {
    // Display each row
}

// Close connection
mysqli_close($connection);