채택완료

전체카테고리 등록

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개

채택된 답변
+20 포인트

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


Copy
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>

답변을 작성하려면 로그인이 필요합니다.