작성일 : 12-05-22 14:41
[템플릿플러그인] 서브 카테고리 출력
|
|
글쓴이 :
관리자
조회 : 18,183
|
function.GetSubCategory.php (1.4K) [14] DATE : 2012-05-22 14:41:01 |
Template_/tpl_plugin/function.GetSubCategory.php
<?php
// 서브 카테고리 출력
function GetSubCategory($cat_id='', $mode='all')
{
$catelist = array();
$len = strlen($cat_id);
$length = $len/3;
$strlen = ($length+1)*3;
if($cat_id) {
// 기본모드는 서브 카테고리 전체 가져옴
if($mode=='all') {
if($length>1) $s_len = ($length - 1)*3;
else $s_len = 3;
$rs = sql_query(" SELECT * FROM ".CM_SHOP_CATEGORY." WHERE view_use = '1' and SUBSTR(cat_id,1,$s_len) = '".SUBSTR($cat_id,0,$s_len)."' and LENGTH(cat_id) = $s_len order by cat_id asc ");
// 현 카테고리에 서브만 가져옴
} elseif($mode=='sub') {
$rs = sql_query(" SELECT * FROM ".CM_SHOP_CATEGORY." WHERE view_use = '1' and SUBSTR(cat_id,1,$len) = '".SUBSTR($cat_id,0,$len)."' and LENGTH(cat_id) = $strlen order by cat_id asc ");
}
} else {
$rs = sql_query(" SELECT * FROM ".CM_SHOP_CATEGORY." WHERE view_use = '1' and LENGTH(cat_id) = 3 order by cat_id asc ");
}
while($row=sql_fetch_array($rs)) {
$strlen=((strlen($row['cat_id'])/3)+1)*3;
$rs2 = sql_query(" SELECT * FROM ".CM_SHOP_CATEGORY." WHERE view_use = '1' and cat_id like '$row[cat_id]%' and LENGTH(cat_id) = $strlen order by cat_id asc ");
$sub=array();
while($row2=sql_fetch_array($rs2)) $sub[] = $row2;
$row['sub'] = $sub;
$catelist[] = $row;
}
return $catelist;
}
?>
|
|