Reputation: 319
I am currently using tinyint to store boolean values in mysql, and am trying to query a database but it is failing. The error I am getting is Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given
which if im not mistaken just means the query didn't work. Before I post the query let me say I am using practically deprecated php for the query, however it's not going live and I just need it to work real quick. I know this stuff is all being updated so feel free to share any relevant materials (I do need to get caught up as it is) however the solution I am looking for is for my old school query. The query is:
$sql = mysql_query("SELECT * FROM contact ORDER BY id ASC WHERE read='0'");
where read is the tinyint in question.
I have tried WHERE read=0
and WHERE read=false
None of these are working, I do appreciate any help in advance!
Upvotes: 0
Views: 219
Reputation: 18833
You need to structure the query correctly:
"SELECT * FROM contact WHERE read=0 ORDER BY id ASC"
WHERE comes before ORDER BY.
Additionally, "mysql_num_rows() expects parameter 1 to be resource" is happening because you're calling a method on a failed query - not a resource. You could get a proper error on your query itself with something like mysql_query("SELECT... your query") or die(mysql_error())
But officially we all suggest moving to PDO or mysqli
And using their respective error reporting utilities.
Upvotes: 4