Home > Backend Development > PHP Tutorial > Why Does `mysqli_num_rows()` Return \'expects parameter 1 to be mysqli_result, boolean given\'?

Why Does `mysqli_num_rows()` Return \'expects parameter 1 to be mysqli_result, boolean given\'?

Mary-Kate Olsen
Release: 2024-11-28 03:28:15
Original
506 people have browsed it

Why Does `mysqli_num_rows()` Return

PHP & MySQL: Fixing mysqli_num_rows() Parameter Error

The error "mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given" indicates that the function is expecting a valid MySQL result object as its first parameter, but is being passed a boolean value.

In this case, the issue is caused by the query used in the mysqli_query() call, which contains a syntax error. The issue is with the SELECT statement:

SELECT users.*, profile.*
FROM users 
INNER JOIN contact_info ON contact_info.user_id = users.user_id 
WHERE users.user_id=3");
Copy after login

The query attempts to perform an inner join between the users and contact_info tables, but there's a missing JOIN clause. The correct query should look like this:

SELECT users.*, profile.*
FROM users 
INNER JOIN profile ON profile.user_id = users.user_id 
WHERE users.user_id=3");
Copy after login

Once the query is fixed, mysqli_query() should return a valid result object, which can then be passed as the first parameter to mysqli_num_rows().

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template