paging an array result in D7 I have a Query like this:

$query = db_select('nid_tid', 'nt')
-&gt;fields('nt')
-&gt;condition('terms', $name,'=');
$result=$query-&gt;execute();

$row=$result-&gt;fetchAssoc();
$nid =$row['nid'];
$ex=explode(',', $nid);
foreach ($ex as $tag_nid)
{
  $out .= $tag_nid;
}


return $out

I want paging this result .for example per 10 result in one page

thank you
You need to extend the query to a PagerDefault, and then use theme_pager() to output the pager links at the end of your content. The rest will be taken care of for you:

$limit = 10;
$query = db_select('nid_tid', 'nt')
  -&gt;fields('nt')
  -&gt;condition('terms', $name,'=');

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

$result = $query-&gt;execute();

$row = $result-&gt;fetchAssoc();
$nid = $row['nid'];
$ex = explode(',', $nid);
foreach ($ex as $tag_nid) {
  $out .= $tag_nid;
}

$out .= theme('pager');