我使用下面的查詢搶從MySQL數據庫的結果:如何計算從MySQL查詢返回的結果總數?
$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
");
返回的結果有可能是500+
我怎麼能算行的總金額此查詢將返回如果有沒有限制,所以我可以顯示給用戶?
我實際上已經嘗試過,並且得到以下錯誤... 您的SQL語法錯誤;請檢查與您的MySQL服務器版本對應的手冊,以便在第10行'SELECT FOUND_ROWS()'附近使用正確的語法。SELECT SQL_CALC_FOUND_ROWS * FROM results r INNER JOIN categories c on r.id = c.result_id INNER JOIN標記t ('purchase','single_family','usda')和r.id = t.result_id WHERE c.name AND(r.scope ='all'或r.scope ='redflagwiki')GROUP BY r.id HAVING COUNT(c.c_id)= 3 ORDER BY r.usefulness DESC LIMIT 10 OFFSET 0 SELECT FOUND_ROWS(); –
這個過程仍然需要通過2個查詢來完成:如果您在提示符下鍵入該內容,請確保在「OFFSET 0」之後添加了分號。在PHP中,執行初始查詢只需添加SQL_CALC_FOUND_ROWS,然後再執行另一個查詢「SELECT FOUND_ROWS();」 –
非常感謝!這很好 –