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!
You need to structure the query correctly:
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 mysqliAnd using their respective error reporting utilities.