What is the purpose of using mysql_num_rows() function in PHP?

The purpose of using the mysql_num_rows() function in PHP is to retrieve the number of rows returned by a SELECT query executed on a MySQL database. This function is useful for determining the number of results returned by a query, which can be used for various purposes such as displaying the count of search results or implementing pagination.

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

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

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

// Display the count of rows
echo "Number of rows: " . $num_rows;