0) { foreach($charid as $c) { $chars[] = "FIND_IN_SET('$c', characters) > 0"; } $chalquery[] = implode(" OR ", $chars); } } if(is_array($catid) && count($catid) > 0) { $categories = array( ); // Get the recursive list. foreach($catid as $cat) { if($cat == "false" || empty($cat) || $cat == -1) continue; $categories = array_merge($categories, recurseCategories($cat)); } // Now format the SQL $cats = array( ); foreach($categories as $cat) { $cats[] = "FIND_IN_SET($cat, catid) > 0 "; } // Now implode the SQL list if(!empty($cats)) $chalquery[] = "(".implode(" OR ", $cats).")"; } if($searchterm) { if($searchtype == "title") $chalquery[] = "title LIKE '%$searchterm%'"; if($searchtype == "summary") $chalquery[] = "summary LIKE '%$searchterm%'"; } if(count($chalquery) > 0) { $chalquery = "WHERE ".implode(" AND ", $chalquery); $query = dbquery("SELECT * FROM ".TABLEPREFIX."fanfiction_challenges $chalquery"); $challenges = dbnumrows($query); if($challenges > 0) $otherresults[] = "$challenges "._CHALLENGES.""; } unset($where, $query, $chars, $cats); } ?>