$result = pager_query($query, 10, 0, NULL, $args);

Currently with above code , I am getting all results with 10 items per page. But I need to display only first 100 records , with 10 items per page. Is this possible with pager_query() or any alternate solution using plain PHP and MySQL?

4 Answers 4


You can pass a $count_query argument to pager_query(), which you can use to control the overall count:


$sql = 'SELECT * FROM my_table';
$count_sql = 'SELECT COUNT(id) FROM my_table LIMIT 100';

$result = pager_query($sql, 10, 0, $count_sql);
  • Tried that , no effect, is there anything to be added additionally?
    – Serjas
    Aug 1, 2013 at 10:22
  • I've never actually tried that, it just made sense logically. I don't think there's any other approach to getting the standard pager_query() to do what you want, if the above doesn't work you'll have to go for a custom implementation
    – Clive
    Aug 1, 2013 at 10:29
  • Try changing to LIMIT 0, 100. Jul 28, 2015 at 11:22

Replace '$args' with '100' in pager_query() and check.

$query = new EntityFieldQuery();
$results = $query->entityCondition('entity_type', 'node')   
          ->entityCondition('bundle', 'your_content_type')
          ->fieldCondition('field_village_schedule_state', 'value', 'your_value','=')

  if (isset($results['node'])) {
       $nodes = node_load_multiple(array_keys($results['node']));
       foreach ($nodes as $row) 
          // Your Code Here for dispaly.

If you need to supply any argument to your query just add them after all the **pager_query arguments like so:**

Example Query:

$query = "SELECT heading, summary, publish_date FROM {news} WHERE category_id = %d ORDER BY publish_date DESC";

$result = pager_query($query, 100, 0, NULL, $cat_id);

So, for the pager_query example above let me explain the arguments:

  1. 1st arg ($query) = The query to be executed.
  2. 2nd arg (10) = $limit The number of query results to display per page.
  3. 3rd arg (0) = $element The integer number of the pager we are working with.
  4. 4th arg (NULL) = $count_query Just put NULL which is the default for this variable.
  5. 5th arg ($cat_id) = The argument that needs to be passed to the query itself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.