Link to home
Start Free TrialLog in
Avatar of jblayney
jblayneyFlag for Canada

asked on

test if query has no results

Hello,

I am trying to do a simple test, I want to know if I do not have any results from a query

this does not work
$result_check_answers->num_rows == 0

this does not work
!$result_check_answers->num_rows

for testing purposed I

echo $result_check_answers->num_rows
and it echoes
 0

I also tried this as well
$result_check_answers->num_rows > 0 and tried to test for more than than 0, but that doesn't work either

How do i test for no results, mysql_num_rows used to work great, but mysqli does not seem to have anything  similar
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
All of the familiar, but obsolete, MySQL functions are mapped 1::1 with their MySQLi equivalents in this article.  See the part named "Find the Number of Rows in the Results Set."
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

What you're doing looks right to me, but I can't see the rest of the code.  Also, beware of PHP loose typing.  Zero and FALSE can mean the same thing, sometimes, but not always.