What is the significance of using the mysql_num_rows function in PHP?

The mysql_num_rows function in PHP is used to retrieve the number of rows returned by a SELECT query executed on a MySQL database. This function is useful for tasks such as determining the number of results in a query result set, validating the success of a query, or iterating through the results.

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

// Execute a SELECT query
$result = mysqli_query($conn, "SELECT * FROM table");

// Check if the query was successful
if($result) {
    // Get the number of rows returned by the query
    $num_rows = mysqli_num_rows($result);
    
    // Output the number of rows
    echo "Number of rows: " . $num_rows;
} else {
    echo "Error executing query: " . mysqli_error($conn);
}

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