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
Mary-Kate OlsenOriginal
2024-11-28 03:28:15540browse

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");

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");

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!

Statement:
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