I wrote this function to get the number of rows in the table for each particular category. I wrote this function, it won't work, and I can't figure out why. function getNumRows($category){ $query = "SELECT * FROM direc WHERE category=\"$category\""; $result = mysqli_query($cxn,$query); if($result){ echo 'query successful'; } else{ echo 'query failed'; } $num = mysqli_num_rows($result); return $num; } I know that $cxn works, so the problem must be with the $query. but I tried the syntax on the mySQL command line and it worked, so what gives here? what is wrong with this function?