What alternative function could be used instead of mysql_num_rows to achieve the desired result?

The mysql_num_rows function is deprecated in newer versions of PHP and should be replaced with mysqli_num_rows or PDOStatement::rowCount to achieve the desired result of getting the number of rows returned by a query.

// Using mysqli_num_rows
$query = mysqli_query($connection, "SELECT * FROM table");
$num_rows = mysqli_num_rows($query);
echo "Number of rows: " . $num_rows;

// Using PDOStatement::rowCount
$stmt = $pdo->query("SELECT * FROM table");
$num_rows = $stmt->rowCount();
echo "Number of rows: " . $num_rows;