Ignore:
Timestamp:
Aug 29, 2004, 6:50:49 PM (20 years ago)
Author:
z0rglub
Message:

search in sub-categories option is available

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_category.inc.php

    r499 r502  
    572572        if (isset($search['fields']['cat']))
    573573        {
    574           $local_clause = 'category_id IN (';
    575           $local_clause.= implode(',',$search['fields']['cat']['words']);
    576           $local_clause.= ')';
    577           array_push($clauses, $local_clause);
     574          if ($search['fields']['cat']['mode'] == 'sub_inc')
     575          {
     576            // searching all the categories id of sub-categories
     577            $search_cat_clauses = array();
     578            foreach ($search['fields']['cat']['words'] as $cat_id)
     579            {
     580              $local_clause = 'uppercats REGEXP \'(^|,)'.$cat_id.'(,|$)\'';
     581              array_push($search_cat_clauses, $local_clause);
     582            }
     583            array_walk($search_cat_clauses,
     584                       create_function('&$s', '$s = "(".$s.")";'));
     585           
     586            $query = '
     587SELECT DISTINCT(id) AS id
     588  FROM '.CATEGORIES_TABLE.'
     589  WHERE '.implode(' OR ', $search_cat_clauses).'
     590;';
     591            echo '<pre>'.$query.'</pre>';
     592            $result = mysql_query($query);
     593            $cat_ids = array();
     594            while ($row = mysql_fetch_array($result))
     595            {
     596              array_push($cat_ids, $row['id']);
     597            }
     598            $local_clause = 'category_id IN (';
     599            $local_clause.= implode(',',$cat_ids);
     600            $local_clause.= ')';
     601            array_push($clauses, $local_clause);
     602          }
     603          else
     604          {
     605            $local_clause = 'category_id IN (';
     606            $local_clause.= implode(',',$search['fields']['cat']['words']);
     607            $local_clause.= ')';
     608            array_push($clauses, $local_clause);
     609          }
    578610        }
    579611
Note: See TracChangeset for help on using the changeset viewer.