while 작동 문제

while 작동 문제

QA

while 작동 문제

본문


if($act == "buy")
{
    if(!count($_POST['ct_chk']))
        alert("주문하실 상품을 하나이상 선택해 주십시오.");
    // 선택필드 초기화
    $sql = " update {$g5['g5_shop_cart_table']} set ct_select = '0' where od_id = '$tmp_cart_id' ";
    sql_query($sql);
    $fldcnt = count($_POST['it_id']);
    for($i=0; $i<$fldcnt; $i++) {
        $ct_chk = $_POST['ct_chk'][$i];
        if($ct_chk) {
            $it_id = $_POST['it_id'][$i];
            // 본인인증, 성인인증체크
            if(!$is_admin) {
                $msg = shop_member_cert_check($it_id, 'item');
                if($msg)
                    alert($msg, G5_SHOP_URL);
            }
            // 주문 상품의 재고체크
            $sql = " select ct_qty, it_name, ct_option, io_id, io_type
                        from {$g5['g5_shop_cart_table']}
                        where od_id = '$tmp_cart_id'
                          and it_id = '$it_id' ";
            $result = sql_query($sql);
            for($k=0; $row=sql_fetch_array($result); $k++) {
                $sql = " select SUM(ct_qty) as cnt from {$g5['g5_shop_cart_table']}
                          where od_id <> '$tmp_cart_id'
                            and it_id = '$it_id'
                            and io_id = '{$row['io_id']}'
                            and io_type = '{$row['io_type']}'
                            and ct_stock_use = 0
                            and ct_status = '쇼핑'
                            and ct_select = '1' ";
                $sum = sql_fetch($sql);
                $sum_qty = $sum['cnt'];
                // 재고 구함
                $ct_qty = $row['ct_qty'];
                if(!$row['io_id'])
                    $it_stock_qty = get_it_stock_qty($it_id);
                else
                    $it_stock_qty = get_option_stock_qty($it_id, $row['io_id'], $row['io_type']);
                if ($ct_qty + $sum_qty > $it_stock_qty)
                {
                    $item_option = $row['it_name'];
                    if($row['io_id'])
                        $item_option .= '('.$row['ct_option'].')';
                    alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");
                }
            }
    

            //장바구니 품절 및 예약 상품
            $sql = " select b.it_2, b.it_soldout, a.it_name
                                  from {$g5['g5_shop_cart_table']} a left join {$g5['g5_shop_item_table']} b on ( a.it_id = b.it_id )
                                  where a.od_id = '$tmp_cart_id'
                                  and a.it_id = '$it_id' ";
            $res = sql_query($sql);
            $cnt = $cnt2 = 0;
            while ($row=sql_fetch_array($res)){
                if ($row['it_soldout'])
                {
                    alert("주문하시려는 상품 중 품절인 상품이 있습니다.");
                }
                if ($row['it_2'] == '1')
                    $cnt = $cnt + 1;
                  
                if ($row['it_2'] == '')
                    $cnt2 = $cnt2 + 1; 
            }
            if ($cnt > 0 && $cnt2 > 0) {
                alert("예약상품과 일반상품은 같이 주문하실 수 없습니다.");
            }
            $sql = " update {$g5['g5_shop_cart_table']}
                        set ct_select = '1',
                            ct_select_time = '".G5_TIME_YMDHIS."'
                        where od_id = '$tmp_cart_id'
                          and it_id = '$it_id' ";
            sql_query($sql);
        }
    }
    if ($is_member) // 회원인 경우
        goto_url(G5_SHOP_URL.'/orderform.php');
    else
        goto_url(G5_BBS_URL.'/login.php?url='.urlencode(G5_SHOP_URL.'/orderform.php'));
}
else if ($act == "alldelete") // 모두 삭제이면
{
    $sql = " delete from {$g5['g5_shop_cart_table']}
              where od_id = '$tmp_cart_id' ";
    sql_query($sql);
}
else if ($act == "seldelete") // 선택삭제
{
    if(!count($_POST['ct_chk']))
        alert("삭제하실 상품을 하나이상 선택해 주십시오.");
    $fldcnt = count($_POST['it_id']);
    for($i=0; $i<$fldcnt; $i++) {
        $ct_chk = $_POST['ct_chk'][$i];
        if($ct_chk) {
            $it_id = $_POST['it_id'][$i];
            $sql = " delete from {$g5['g5_shop_cart_table']} where it_id = '$it_id' and od_id = '$tmp_cart_id' ";
            sql_query($sql);
        }
    }
}

 

이 소스에서 //장바구니 품절 및 예약 상품 부분인데

while ($row=sql_fetch_array($res)){

                if ($row['it_soldout'])
                {
                    alert("주문하시려는 상품 중 품절인 상품이 있습니다.");
                }

                if ($row['it_2'] == '1')
                    $cnt = $cnt + 1;
                  
                if ($row['it_2'] == '')
                    $cnt2 = $cnt2 + 1; 
            }

 

부분이 작동이 되지 않습니다.

 

오로지 체크한 것 중 1번 상품값만 해당이 되네요.

 

어떤 문제일까요?

 

이 질문에 댓글 쓰기 :

답변 1

if ($row['it_2'] == '')
    $cnt2 = $cnt2 + 1; 

이 부분이 왜 이렇게 코딩이 되었을까요?
질문에 대한 답은 될 수 없겠지만
같은 것을 비교해서 사용할거라면 위 부분이

elseif ($row['it_2'] == '')
    $cnt2 = $cnt2 + 1; 로 
    
elseif로 처리하는 것이 좋지 않을까 보여지네요.

말씀 너무 감사합니다

말씀해주신대로 수정했습니다

그래도 여전히 안되네요

지금 너무 스트레스 받네요 ㅠㅠ

it_2 외에도

현재 it_2가 1이면 ct_reserve가 1, 비어있으면 ct_normal이 1이 되게 해서

각각 그것도 들어가 있는 상태입니다.

$sql = " select ct_reserve, ct_normal
                        from {$g5['g5_shop_cart_table']}
                        where od_id = '$tmp_cart_id'
                          and it_id = '$it_id' ";
            $res = sql_query($sql);

while ($row=sql_fetch_array($res)){

if ($row['ct_reserve'] > 0 && $row['ct_normal'] > 0 ) {

alert("예약상품과 일반상품은 같이 주문하실 수 없습니다.");

}

}

이런 것도 구성해보았지만 전혀 동작하지 않더군요 ㅠㅠ

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

회원로그인

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