How to call limited data items per page? I am using one custom module, which is getting data from the database, with the following code.

function rs_get_doors() {
  $doors = array();
  $doors_nids =  db_select('node', 'n')
  $doors_nids = $door_nids-&gt;extend('PagerDefault')-&gt;limit(10);
    -&gt;condition('n.type', 'vivarium_door')
    -&gt;fields('n', array('nid'))
    -&gt;orderBy('n.title', 'ASC')
    -&gt;execute()
    -&gt;fetchCol();

  foreach ($doors_nids as $nid) {
    $wrapper = entity_metadata_wrapper('node', $nid);
    $doors[$nid] = array(
      'name' =&gt; $wrapper-&gt;title-&gt;value(),
      'fee_nid' =&gt; $wrapper-&gt;field_fee_category-&gt;value()-&gt;nid,
    );
  }

  uasort($doors, 'rs_doors_natural_sort');

  return $doors;
}


it is getting thousands of nodes at time in a single page and it takes too much time to load.

So I think I need to paginate the query. How can I achieve this?
$doors_nids = db_select('node', 'n')

-&gt;condition('n.type', 'vivarium_door')

-&gt;fields('n', array('nid'))

-&gt;orderBy('n.title', 'ASC')

-&gt;extend('PagerDefault')-&gt;limit(10)

-&gt;execute()

-&gt;fetchCol();


Hopes this will helps you.