Drupal 6 Pager not working I am using pager_query and theme_pager function as below.But unfortunately the pager is not getting displayed.Please help. 

function advanced_product_search() {
    $output = "";

    $sectors = $material_types = $resource_types = array();
    $where_array = array();
    $node_data = array();
    $product_query = "SELECT n.* FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid ";
    $product_count_query = "SELECT COUNT(DISTINCT(n.nid)) FROM {node} n 
        INNER JOIN {term_node} tn ON n.nid = tn.nid ";

    $product_query .= " WHERE n.type = 'product' ";
     if(isset($_POST['keyword']) &amp;&amp; !empty($_POST['keyword'])){
        $key_word = check_plain($_POST['keyword']);
        $product_query.= " AND n.title LIKE '%$key_word%' ";
        $product_count_query.=" AND n.title LIKE '%$key_word%' ";
    }

    if(!empty($_POST['sector'])){
      $sectors = $_POST['sector'];
    }

    if(!empty($_POST['material_type'])){
      $material_types = $_POST['material_type'];
    }

    if(!empty($_POST['resource_type'])){
      $resource_types = $_POST['resource_type'];
    }

    $terms = array_merge($sectors ,$material_types ,$resource_types);
    if(!empty($terms)){
      $count = 1;
      $terms_list = "";
      foreach($terms as $tid){
        if($count &lt; count($terms)){
          $terms_list.="$tid,";
        }else{
          $terms_list.="$tid";
        }
        $count++;
      }
      $product_query.=" AND tn.tid IN ($terms_list)";
      $product_count_query.=" AND tn.tid IN ($terms_list)";
    }

    $product_query.=" GROUP BY n.nid ORDER BY n.changed DESC ";
    $product_count_query.=" GROUP BY n.nid ORDER BY n.changed DESC ";

    $product_array = array();
    $product_query_result = pager_query($product_query, 5, 0, $product_count_query);
    while ($node = db_fetch_object($product_query_result)) {
      $node_data = node_load($node-&gt;nid);

      if($_POST['accredited'] == 'on'){
        if(empty($node_data-&gt;field_right_way_accredited[0]['value']) || !$node_data-&gt;field_right_way_accredited[0]['value']){
          continue;
        }
      }

      $product_array[] = array(
        'nid'=&gt;$node_data-&gt;nid,
        'title'=&gt;$node_data-&gt;title,
        'price'=&gt;$node_data-&gt;sell_price,
        'image'=&gt;$node_data-&gt;field_image_cache[0]['filepath'],
        'url'=&gt; $node_data-&gt;path
      );
    }

    $output .= theme('ssa_product_search_template', $product_array);
    $output .= theme('pager', NULL, 5, 0);
    return $output;
}
Solved this problem by correcting the fourth argument of pager_query function i.e $product_count_query. 

Pager query takes the fourth argument as an SQL query to count the number of matching records.It should a valid sql query.