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, ct_reserve, ct_normal
                        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 ct_reserve, ct_normal
                        from {$g5['g5_shop_cart_table']}
                        where od_id = '$tmp_cart_id'
                          and it_id = '$it_id' ";
            $check_reserve = $check_normal = 0; 
            $result = sql_query($sql);
            while ($row=sql_fetch_array($result)){
                $check_reserve+= $row['ct_reserve'];
                $check_normal+= $row['ct_normal'];
            }
            echo $check_normal;
            echo $check_reserve;
            if ( $check_reserve && $check_normal ) 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'));
}

 

에서

 


// 예약 상품
$sql = " select ct_reserve, ct_normal
              from {$g5['g5_shop_cart_table']}
              where od_id = '$tmp_cart_id'
              and it_id = '$it_id' ";
$check_reserve = $check_normal = 0;
$result = sql_query($sql);
while ($row=sql_fetch_array($result)){
           $check_reserve+= $row['ct_reserve'];
           $check_normal+= $row['ct_normal'];
       }
echo $check_normal;
echo $check_reserve;
if ( $check_reserve && $check_normal ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');

 

이 부분인데 반복이 되는게 아니라

 

장바구니가 비워져 있을 때 첫번째 담는 상품의 정보가 표시되는거 같아요

 

그 뒤로는 다른 상품을 담아도 바뀌지 않구요

 

for 구문으로 변경하고 k값을 구해도 1만 나오네요

 

1번 돌고 끝나는거 같아요

 

echo $_POST['ct_chk'][$i]; 하니까 상품 하나의 it_id만 나오고

 

뭐가 잘못된건가요? ㅠㅠ

 

DB에는 정상적으로 들어가 있습니다.

 

990320945_1599116417.1362.jpg

이 질문에 댓글 쓰기 :

답변 2

쿼리문 보시면 where od_id = '$tmp_cart_id' and it_id = '$it_id'

 

$it_id부분이 필요한건가요? 지우시면될것같은데요

it_id값을 어디서 가져오는지는 모르겠으나 이값때문에 하나만 찍히는것같습니다

 

음 예약상품을 불러오는기준점을 잡아야할것같은데요
장바구니에서 예약상품은 무엇이며 예약상품을 구분하는 코드는 어떤것이고 또 체크한 장바구니 상품에서의 예약상품..? 전체적인 기능과 구조를 알수없으니 ㅠㅠ 조언을드리기가 곤란하네요

$sql = " select ct_reserve, ct_normal
              from {$g5['g5_shop_cart_table']}
              where od_id = '$tmp_cart_id'
              and it_id = '$it_id' ";
echo $sql;
echo '<br>';
$check_reserve = $check_normal = 0;
$result = sql_query($sql);
while ($row=sql_fetch_array($result)){
print_r2($row);
echo '<br>';
           $check_reserve+= $row['ct_reserve'];
           $check_normal+= $row['ct_normal'];
       }
echo $check_normal;
echo $check_reserve;

echo '<hr>';

exit;

 

요런식으로 요소요소에 데이터 및 query에 이상이 없는지 먼저 확인해보세요.

sql 찍힌걸 쿼리분석기로 돌려서 에러가 있는지 데이터가 원하는데로 검색되어져 나오는지

안나온다면 쿼리문에 문제가 없는지부터 확인하고요. 문제가 없다면 print_r을 통해 데이터가 어떻게 나오는지 확인해보세요.

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

회원로그인

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