3
SELECT `p`.`name`, `f`.*
        FROM `players` `p`, `folks` `f`
        WHERE `p`.`id` = `f`.`guid` 
        AND `f`.`deleted` = 0
        AND `first` = {$id} 
        AND `text` LIKE ?
        LIMIT 10

As you can see I'm using a LIMIT condition here. I need to count all results that will be matched without LIMIT cond.

I've tried using: FOUND_ROWS(); but I got problems with using it, as it doesn't return 'all' results anywhere.

mleko
  • 11,650
  • 6
  • 50
  • 71
Isarius
  • 91
  • 6
  • Not really: http://stackoverflow.com/questions/2439829/how-to-count-all-rows-when-using-select-with-limit-in-mysql-query – Isarius Oct 10 '11 at 23:14

1 Answers1

3

The following should do :) Important is the SQL_CALC_FOUND_ROWS, otherwise FOUND_ROWS() won't work!

SELECT SQL_CALC_FOUND_ROWS `p`.`name`, `f`.*
    FROM `players` `p`, `folks` `f`
    WHERE `p`.`id` = `f`.`guid` 
    AND `f`.`deleted` = 0
    AND `first` = {$id} 
    AND `text` LIKE ?
    LIMIT 10


SELECT FOUND_ROWS();
Anonymous
  • 3,679
  • 6
  • 29
  • 40
  • Oh, I've now made `SELECT FOUND_ROWS();` in separeted query variable , and it worked. Thank you mate :). – Isarius Oct 10 '11 at 23:22