I am using the following query to grab results from a MySQL database:
$query = $this->db->query("
SELECT * FROM results r
INNER JOIN categories c on r.id = c.result_id
INNER JOIN tags t on r.id = t.result_id
WHERE c.name in ('$purpose', '$prop_type', '$loan_type')
$tag_string
AND ( r.scope = 'all' OR r.scope = '$subdomain' )
GROUP BY r.id
HAVING COUNT(c.c_id) = 3
ORDER BY r.usefulness DESC
LIMIT 10 OFFSET $offset
");
The returned results can potentially be 500+
How can I count the total amount of rows this query would return if there were no limit so I can display it to the user?
SQL_CALC_FOUND_ROWS and “SELECT FOUND_ROWS()” is what you want:
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows