I am having trouble with the query in this code. The problem is one I have had before, the $num = mysql_num_rows($result); part gives me a MySQL error saying it expected a resource. Usually when I have this error it is because I misplaced a single quote some where, but after looking I cannot find any problem, though this query is a bit more complex than what I usually have to deal with.
//connect to the database and stuff
$last_year = idate("Y")-1;
$month = date("m");
$day = date("d");
$query = "SELECT bills.b_id, bills.c_id, bills.grand_total, bills.void, bills.date_added,
customers.b_name, customers.l_name, customers.f_name, customers.phone
FROM bills, customers
WHERE bills.c_id = customers.c_id
AND bills.void = '0'
AND date_added BETWEEN '".$last_year."-".$month."-".$day."' AND CURDATE()";
$result = mysql_query($query);
mysql_close($link);
$num = mysql_num_rows($result);
EDIT:
Although I already know the mysql_close() function is not the problem I went ahead and removed it and my code still does not work. This EXACT same code (other than the query) works in nearly a dozen other pages. The problem is in the query, the MySQL error (as stated before) is mysql_num_rows() expects parameter 1 to be resource. I am working on getting the specific error now.
Add some error handling to your code.
(in “real” production code you might not want to display the actual query and error message to just any arbitrary user though).
see also: http://docs.php.net/mysql_error