6

So I have my query as so...

$records = ORM::factory('category');

Add a WHERE clause as so...

$records = $records->where('categoryid', 'LIKE', 'aa');

Grab a count for pagination as so...

$count = $records->count_all();

And my where clause gets cleared away as so...

SELECT `categories`.* FROM `categories` LIMIT 20 OFFSET 0

With this line commented out

//$count = $records->count_all();

My SQL looks just fine...

SELECT `categories`.* FROM `categories` WHERE `categoryid` LIKE 'aa' LIMIT 20 OFFSET 0

Is it possible to use a single query the way I'm trying to or do I have to make two duplicate identical queries? One for the count, and one for the actual results...

Thanks!

Serhiy
  • 2,505
  • 3
  • 33
  • 49

1 Answers1

12

Use special reset(FALSE) call:

$records = $records->where('categoryid', 'LIKE', 'aa');
$records->reset(FALSE); // !!!!
$count = $records->count_all();
$categories = $records->find_all();
biakaveron
  • 5,493
  • 1
  • 16
  • 20
  • Thank you very much for a very brief and clear answer. Not to impose but you wouldn't happen to know by chance how to do that with just the database module? Particularly this question: http://stackoverflow.com/questions/6617760/when-using-kohana-db-how-does-one-avoid-duplicate-code-when-needing-a-count-for Wellp anyways... thank you again... – Serhiy Jul 08 '11 at 01:03