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']) && !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 < 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->nid);
if($_POST['accredited'] == 'on'){
if(empty($node_data->field_right_way_accredited[0]['value']) || !$node_data->field_right_way_accredited[0]['value']){
continue;
}
}
$product_array[] = array(
'nid'=>$node_data->nid,
'title'=>$node_data->title,
'price'=>$node_data->sell_price,
'image'=>$node_data->field_image_cache[0]['filepath'],
'url'=> $node_data->path
);
}
$output .= theme('ssa_product_search_template', $product_array);
$output .= theme('pager', NULL, 5, 0);
return $output;
}
$product_count_query
is not returning 0, or the pager will think there is no items to show.