paging an array result in D7
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');