From 54c907ce9d04194cbbd5b506b8afcafe19dd6948 Mon Sep 17 00:00:00 2001 From: z0rglub Date: Sun, 29 Aug 2004 16:50:49 +0000 Subject: search in sub-categories option is available git-svn-id: http://piwigo.org/svn/trunk@502 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/functions_category.inc.php | 40 ++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index d4fb55aad..5cb0e727f 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -571,10 +571,42 @@ function initialize_category( $calling_page = 'category' ) if (isset($search['fields']['cat'])) { - $local_clause = 'category_id IN ('; - $local_clause.= implode(',',$search['fields']['cat']['words']); - $local_clause.= ')'; - array_push($clauses, $local_clause); + if ($search['fields']['cat']['mode'] == 'sub_inc') + { + // searching all the categories id of sub-categories + $search_cat_clauses = array(); + foreach ($search['fields']['cat']['words'] as $cat_id) + { + $local_clause = 'uppercats REGEXP \'(^|,)'.$cat_id.'(,|$)\''; + array_push($search_cat_clauses, $local_clause); + } + array_walk($search_cat_clauses, + create_function('&$s', '$s = "(".$s.")";')); + + $query = ' +SELECT DISTINCT(id) AS id + FROM '.CATEGORIES_TABLE.' + WHERE '.implode(' OR ', $search_cat_clauses).' +;'; + echo '
'.$query.'
'; + $result = mysql_query($query); + $cat_ids = array(); + while ($row = mysql_fetch_array($result)) + { + array_push($cat_ids, $row['id']); + } + $local_clause = 'category_id IN ('; + $local_clause.= implode(',',$cat_ids); + $local_clause.= ')'; + array_push($clauses, $local_clause); + } + else + { + $local_clause = 'category_id IN ('; + $local_clause.= implode(',',$search['fields']['cat']['words']); + $local_clause.= ')'; + array_push($clauses, $local_clause); + } } // adds brackets around where clauses -- cgit v1.2.3