mysqli_num_rows() Function Error in PHP and MySQL: A Detailed Guide
Issue:
When calling the mysqli_num_rows() function, the error "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" is encountered. This error indicates a problem with the parameter passed to the function.
Analysis and Resolution:
The mysqli_num_rows() function expects the first parameter to be a valid mysqli_result object. In the provided code, $dbc is mistakenly used as the parameter. However, examining the code reveals that $dbc is the result of a mysqli_query() call.
The actual issue lies in the query itself. The query attempts to perform an INNER JOIN between the "users" and "profile" tables. However, there is no explicit JOIN condition specified in the query. This results in the query returning false, which is then passed to the mysqli_num_rows() function and triggers the error.
To resolve this issue, you need to specify a valid JOIN condition in the query. In this case, you should likely JOIN "users" and "profile" on their user_id fields. Once the query is corrected, it should return a valid mysqli_result object, which can then be passed to the mysqli_num_rows() function.
Corrected Query:
$dbc = mysqli_query($mysqli, " SELECT users.*, profile.* FROM users INNER JOIN profile ON users.user_id = profile.user_id WHERE users.user_id=3 ");
With this adjustment, the query should execute successfully, returning a mysqli_result object that can be used by the mysqli_num_rows() function without triggering the error.
The above is the detailed content of Why Does mysqli_num_rows() Return \'expects parameter 1 to be mysqli_result, boolean given\'?. For more information, please follow other related articles on the PHP Chinese website!