Home >Database >Mysql Tutorial >Why does `mysqli_num_rows()` return 'expects parameter 1 to be mysqli_result, boolean given'?
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
The error message "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" arises when trying to use the mysqli_num_rows() function on a boolean value instead of a valid MySQL result set (mysqli_result).
In the provided code, the error occurs on line 22:
if (mysqli_num_rows($dbc) == 0) {
The variable $dbc is assigned on line 13 using the mysqli_query() function. However, examining the query reveals an error:
$dbc = mysqli_query($mysqli,"SELECT users.*, profile.* FROM users INNER JOIN contact_info ON contact_info.user_id = users.user_id WHERE users.user_id=3");
The query attempts to join the "users" and "profile" tables using an "INNER JOIN," but there is no join condition between "profile" and any other table. As a result, the query returns false (boolean false).
To resolve the error, the query must be corrected to include a proper join condition. Here is the 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 correction, the query will return a valid MySQL result set, allowing mysqli_num_rows() to operate correctly.
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!