How can the error "Fatal error: Call to undefined method mysqli::num_rows()" be resolved in PHP?

The error "Fatal error: Call to undefined method mysqli::num_rows()" occurs when trying to use the num_rows() method on a mysqli object, which is incorrect. To resolve this issue, you should use the mysqli_result object returned by a query to access the num_rows property instead.

// Incorrect usage leading to the error
$result = $mysqli->query("SELECT * FROM table");
$num_rows = $mysqli->num_rows();

// Correct way to get the number of rows
$result = $mysqli->query("SELECT * FROM table");
$num_rows = $result->num_rows;