tags:

views:

21

answers:

1

I'd like to display the total of number of records a query found and then the search results below it. Currently I do this with 2 queries like so:

$total_results = $mydb->count($qry);
$r = $mydb->find($qry)
          ->skip($pagination*$results_per_page)
          ->limit($results_per_page);

Is it possible to somehow combine the count and find queries into a single call that returns both info? Or can this only be done by issuing 2 separate queries like I'm already doing?

A: 

I asked a similar question, looks like you'll have to run it twice.

http://stackoverflow.com/questions/3010744/how-to-handle-pagination-queries-properly-with-mongodb-and-php

luckytaxi