1차가 같은 2차 분류만 뽑기

1차가 같은 2차 분류만 뽑기

QA

1차가 같은 2차 분류만 뽑기

본문

현재

1차 - 지역

2차 - 컨텐츠

3차 - 예약

 

이렇게 분류로 해서 뿌려주고 있는데

처음 화면에서

1차 분류로 지역을 선택하고

다음 페이지에서 1차 지역에 맞는 2차 분류들을 뽑아오고 싶습니다..

 

현재는 1차 분류 선택 후 다음페이지에 모든 2차분류가 다 추출되고 있습니다.

10 선택시 1010 1020 1030 만 노출

 

listcategory.php 파일들 뒤져봐도 너무 어렵네요ㅠㅠ

 

1차 추출 코드


<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
 
$str = '';
$exists = false;
 
$ca_id_len = strlen($ca_id);
$len2 = $ca_id_len + 2;
$len4 = $ca_id_len + 4;
 
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '$ca_id%' and length(ca_id) = $len2 and ca_use = '1' order by ca_order, ca_id ";
$result = sql_query($sql);
while ($row=sql_fetch_array($result)) {
 
    $row2 = sql_fetch(" select count(*) as cnt from {$g5['g5_shop_item_table']} where (ca_id like '{$row['ca_id']}%' or ca_id2 like '{$row['ca_id']}%' or ca_id3 like '{$row['ca_id']}%') and it_use = '1'  ");
 
    $str .= '<li><a href="'.G5_THEME_URL.'/html/serchpick.php"><h2 class="'.$row['ca_id'].'">'.$row['ca_name'].'</h2> <span>준비된 컨텐츠 '.$row2['cnt'].'개</span> </a><i class="xi-angle-right"></i></li>';
    $exists = true;
}
 
if ($exists) {
 
    // add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
    add_stylesheet('<link rel="stylesheet" href="'.G5_SHOP_SKIN_URL.'/style.css">', 0);
?>
 
<!-- 상품분류 1 시작 { -->
<div class="serch_list">
    <!-- <h2>현재 상품 분류와 관련된 분류</h2> -->
    <ul>
        <?php echo $str; ?>
    </ul>
</div>
<!-- } 상품분류 1 끝 -->
 
<?php }

 

2차 추출 코드


<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
 
$str = '';
$exists = false;
 
$depth2_ca_id = substr($ca_id, 0, 2);
 
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}%' and length(ca_id) = 4 and ca_use = '1' order by ca_id, ca_order ";
$result = sql_query($sql);
while ($row=sql_fetch_array($result)) {
    if (preg_match("/^{$row['ca_id']}/", $ca_id))
        $sct_ct_here = 'sct_ct_here';
    else
        $sct_ct_here = '';
    $str .= '<li><a href="'.shop_category_url($row['ca_id']).'" class="'.$sct_ct_here.'">'.$row['ca_name'].' <span>준비된 컨텐츠 보러가기</span> </a><i class="xi-angle-right"></i></li>';
    $exists = true;
}
 
if ($exists) {
 
    // add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
    add_stylesheet('<link rel="stylesheet" href="'.G5_SHOP_SKIN_URL.'/style.css">', 0);
?>
 
<!-- 상품분류 3 시작 { -->
    <ul>
        <?php echo $str; ?>
    </ul>
<!-- } 상품분류 3 끝 -->
 
<?php }

이 질문에 댓글 쓰기 :

답변 1

2차" 페이지에서 이 변수가
$depth2_ca_id

안 넘어 오는 것 같습니다.

 

다음은 추천 query입니다.

1차 query

$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '__' and length(ca_id) = $len2 and ca_use = '1' order by ca_order, ca_id ";
$result = sql_query($sql);

2차 query

 

$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}__' and length(ca_id) = 4 and ca_use = '1' order by ca_id, ca_order ";
$result = sql_query($sql);

말씀해주신대로 다시 해보니 추출은 되었는데
1차에서 10 1010 101010 101020 1020 1030 추출이 되고
2차에도 동일합니다.

1차에서 10 20 30 40 50 60
그리고 만약 10 클릭시
2차에서 1010 1020 1030 만 추출을 하고싶습니다ㅠㅠ

1차 수정본
$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, ca_id ";

2차 수정본
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}%' and ca_use = '1' order by ca_id, ca_order ";

1번 echo $sql
select ca_id, ca_name from g5_shop_category where ca_id like '%' and ca_use = '1' order by ca_order, ca_id

2번 echo $sql
select ca_id, ca_name from g5_shop_category where ca_id like '%' and ca_use = '1' order by ca_id, ca_order select ca_id, ca_name from g5_shop_category where ca_id like '%' and ca_use = '1' order by ca_id, ca_order

입니다

mysql like에서 _ (undersocre)가 의미가 있는 것입니다.

1차 수정본
$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, ca_id ";

2차 수정본
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}%' and ca_use = '1' order by ca_id, ca_order ";

이것은

1차 수정본
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '__%' and ca_use = '1' order by ca_order, ca_id ";

2차 수정본
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}__' and ca_use = '1' order by ca_id, ca_order ";

이렇게 해 보세요.

여전히 2차페이지에서 10 1010 101010 101020 1020 1030 1040 20 2020 201010 ... 이렇게 전부 나옵니다ㅠ

구현 설명을 추가하자면
현재는 serch.php 에서
1차에서 10 20 30 40 50 60 카테고리 추출 후 링크 클릭시
serchpick.php로 이동합니다.
1차에서 10을 선택시
serchpick.php에서는 1010 1020 1030을 추출해야 합니다.

꼭 이렇게 php 파일을 변경하지 않고도 다른 구현 방법이 있다면 추천 부탁드립니다..ㅠ

2차에서
여전히 2차페이지에서 10 1010 101010 101020 1020 1030 1040 20 2020 201010 ... 이렇게 전부 나옵니다ㅠ
==
라면

$depth2_ca_id
변수가 안 넘어 온 거 같습니다.
%가 아니라 _ _ 두 개로 바꾸세요. (공백 없이)

번거롭게 해드려서 죄송합니다ㅠ 헷갈려서 그러는데

첫번째 페이지 serch.php에
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '__' and ca_use = '1' order by ca_order, ca_id ";

두번째 페이지 serchpick.php에
$sql = " select ca_id, ca_name from {$g5['g5_shop_category_table']} where ca_id like '${depth2_ca_id}__' and ca_use = '1' order by ca_id, ca_order ";

이 쿼리문이 맞을까요??

답변을 작성하시기 전에 로그인 해주세요.
전체 123,128 | RSS
QA 내용 검색

회원로그인

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