Quick tip for debugging MySQL database problems:
If you get an invalid result resource error, it means that your query is malformed. It is nothing to do with zero rows of data being found.
In the PHP documentation you will see verbose MySQL query examples that do too much error checking in my opinion. As long as your code produces valid queries, you should never see the invalid resource error. And if you do see these errors, so will your users, even if you report the errors to the browser.
So all you need to check for is number of rows returned after a "select" query and number of affected rows after other queries if you need to know.
p.s. I always form my query in a string before executing the mysql_query() function since it is very easy to insert an echo or die to view the offending query when de-bugging your code e.g.
<?php
$q = "SELECT `name` FROM `categories` WHERE `id`='$cat'";
echo "Q: $q "; // Debug it
die("Q: $q "); // Or break at this point
connect_to_db();
$r = mysql_query($q);
?>
Once the problem is resolved, I remove any debug code like this.