전체카테고리 등록

전체카테고리 등록

QA

전체카테고리 등록

본문

9f32a0c950ceb86c96ab367fec6e8ddf_1504164477_9575.png
저기전체카테고리에 메뉴들을넣고싶은데..어떻해하는지모르겠습니다...


<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가

function get_mshop_category($ca_id, $len)
{
    global $g5;

    $sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']}
                where ca_use = '1' ";
    if($ca_id)
        $sql .= " and ca_id like '$ca_id%' ";
    $sql .= " and length(ca_id) = '$len' order by ca_order, ca_id ";

    return $sql;
}
?>
<button type="button" id="menu_open">전체카테고리</button>
<div id="category">
    <div class="ct_wr">
        <?php
        $mshop_ca_href = G5_SHOP_URL.'/list.php?ca_id=';
        $mshop_ca_res1 = sql_query(get_mshop_category('', 2));
        for($i=0; $mshop_ca_row1=sql_fetch_array($mshop_ca_res1); $i++) {
            if($i == 0)
                echo '<ul class="cate">'.PHP_EOL;
        ?>
            <li class="cate_li_1">
                <a href="<?php echo $mshop_ca_href.$mshop_ca_row1['ca_id']; ?>" class="cate_li_1_a"><?php echo get_text($mshop_ca_row1['ca_name']); ?></a>
                <?php
                $mshop_ca_res2 = sql_query(get_mshop_category($mshop_ca_row1['ca_id'], 4));

                for($j=0; $mshop_ca_row2=sql_fetch_array($mshop_ca_res2); $j++) {
                    if($j == 0)
                        echo '<ul class="sub_cate sub_cate1">'.PHP_EOL;
                ?>
                    <li class="cate_li_2">
                        <a href="<?php echo $mshop_ca_href.$mshop_ca_row2['ca_id']; ?>"><?php echo get_text($mshop_ca_row2['ca_name']); ?></a>
                    </li>
                <?php
                }

                if($j > 0)
                    echo '</ul>'.PHP_EOL;
                ?>
            </li>
        <?php
        }

        if($i > 0)
            echo '</ul>'.PHP_EOL;
        else
            echo '<p class="no-cate">등록된 분류가 없습니다.</p>'.PHP_EOL;
        ?>
    </div>
    <button type="button" class="close_btn">전체카테고리<span class="sound_only">닫기</span></button>
</div>

<script>
$(function (){
    var $category = $("#category");

    $("#menu_open").on("click", function() {
        $category.css("display","block");
    });

    $("#category .close_btn").on("click", function(){
        $category.css("display","none");
    });
});
$(document).mouseup(function (e){
 var container = $("#category");
 if( container.has(e.target).length === 0)
 container.hide();
});
</script>

방법좀가르쳐주세요..고수님들 제발..



이 질문에 댓글 쓰기 :

답변 1

재귀로 변경해서 처리하였습니다 



function get_mshop_category($ca_id, $ca_name)
{
	global $g5;
	//하위메뉴 검사
	$ca_len=intval(strlen($ca_id)/2);
	$str = "<li class='cate_li_{$ca_len}'><a href='".G5_SHOP_URL."/list.php?ca_id={$ca_id}' class='cate_li_{$ca_len}_a'>".get_text($ca_name)."</a>";
	$sql = " select ca_id, ca_name 
	from {$g5['g5_shop_category_table']} 
	where ca_id like '{$ca_id}__' 
	AND ca_use = '1' 
	order by ca_order ";
	$result=sql_query($sql);
	if(sql_num_rows($result)){
		
		$str.="<ul class='sub_cate sub_cate{$ca_len}'>";
		while($row=sql_fetch_array($result)){
			$str.=	get_mshop_category($row[ca_id], $row[ca_name]); 
		}
		$str.="</ul>";
	}
	$str.= "</li>"; 
	return $str;
}
?>
<button type="button" id="menu_open">전체카테고리</button>
<div id="category">
    <div class="ct_wr">
       <?
       $sql = " select ca_id, ca_name 
	from {$g5['g5_shop_category_table']} 
	where  length(ca_id) = '2' 
	AND ca_use = '1' 
	order by ca_order";
	$result=sql_query($sql); 
	$str = "";
	while($row=sql_fetch_array($result)){
		$str .="<ul class='cate'>";
		$str.=	get_mshop_category($row[ca_id], $row[ca_name]); 
		$str.="</ul>";
	}
	if($str){
		echo $str; 
	}
	else{
		echo '<p class="no-cate">등록된 분류가 없습니다.</p>'.PHP_EOL;
	}
       ?>
    </div>
    <button type="button" class="close_btn">전체카테고리<span class="sound_only">닫기</span></button>
</div>
<script>
$(function (){
    var $category = $("#category");
    $("#menu_open").on("click", function() {
        $category.css("display","block");
    });
    $("#category .close_btn").on("click", function(){
        $category.css("display","none");
    });
});
$(document).mouseup(function (e){
 var container = $("#category");
 if( container.has(e.target).length === 0)
 container.hide();
});
</script>
답변을 작성하시기 전에 로그인 해주세요.
전체 123,158 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT