$query->limit(10) gives fatal error I am trying to develop a simple module in Drupal 7. I want to return a table with some data in a function, which i am able to achieve. I am stuck in the pager part though.

I used

pager_default_initialize($total, 10);
$html .= theme('pager', array('quantity',$total));


and I can see the pager below my list, also I have 21 records for now and it shows &lt;&lt; &lt; 1 2 3 > >> which means it calculating 10 records each.

But my issue here is I can see all the 21 records at once regardless of whichever page I go to. I suppose I have goofed up my page_query.
When I tried using $query-&gt;limit(10) it gives error Fatal error: 


  Call to undefined method SelectQuery::limit() in C:\xampp\htdocs...............


If I comment $query-&gt;limit, there's no error but it does not work completely.
This is my query

$query = db_select('profile');
$query-&gt;fields('profile', array('id', 'name', 'store_name', 'company', 'city', 'email', 'phone'));
$query-&gt;orderBy('id', 'DESC');
$query-&gt;extend('PagerDefault')-&gt;limit(10);
//$query-&gt;limit(10);
$results = $query-&gt;execute();


Please help!

Thanks in advance! :)
extend() isn't chain-able, it returns a new extended query object, so you need to assign the result back to the query object, e.g.

$query = $query-&gt;extend('PagerDefault')-&gt;limit(10);


Otherwise the query won't actually be extended and won't have the limit() method, hence the error you're getting.