$sql='SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('.$str_tids.') AND n.status = 1 AND n.moderate = 0 ORDER BY '.$order;
$sql_count='SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('.$str_tids.') AND n.status = 1 AND n.moderate = 0';
$sql='SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('.$placeholders.') AND n.status = 1 AND n.moderate = 0 ORDER BY '.$order;
$sql_count='SELECT COUNT(DISTINCT(n.nid)) FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE tn.tid IN ('.$placeholders.') AND n.status = 1 AND n.moderate = 0';
}
else{
$args=array();
$joins='';
$wheres='';
foreach($descendant_tidsas$index=>$tids){
$joins.=' INNER JOIN {term_node} tn'.$index.' ON n.nid = tn'.$index.'.nid';
$wheres.=' AND tn'.$index.'.tid IN ('.implode(',',$tids).')';
$wheres.=' AND tn'.$index.'.tid IN ('.$placeholders.')';
$args=array_merge($args,$tids);
}
$sql='SELECT DISTINCT(n.nid), n.sticky, n.title, n.created FROM {node} n '.$joins.' WHERE n.status = 1 AND n.moderate = 0 '.$wheres.' ORDER BY '.$order;
$sql_count='SELECT COUNT(DISTINCT(n.nid)) FROM {node} n '.$joins.' WHERE n.status = 1 AND n.moderate = 0 '.$wheres;