테스트 사이트 - 개발 중인 베타 버전입니다

while 반복이 안됩니다 채택완료

블랑숑 5년 전 조회 2,413

</p>

<p>if($act == "buy")

{

    if(!count($_POST['ct_chk']))

        alert("주문하실 상품을 하나이상 선택해 주십시오.");</p>

<p>    // 선택필드 초기화

    $sql = " update {$g5['g5_shop_cart_table']} set ct_select = '0' where od_id = '$tmp_cart_id' ";

    sql_query($sql);</p>

<p>    $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];</p>

<p>            // 본인인증, 성인인증체크

            if(!$is_admin) {

                $msg = shop_member_cert_check($it_id, 'item');

                if($msg)

                    alert($msg, G5_SHOP_URL);

            }</p>

<p>            // 주문 상품의 재고체크

            $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);</p>

<p>            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'];</p>

<p>                // 재고 구함

                $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']);</p>

<p>                if ($ct_qty + $sum_qty > $it_stock_qty)

                {

                    $item_option = $row['it_name'];

                    if($row['io_id'])

                        $item_option .= '('.$row['ct_option'].')';</p>

<p>                    alert($item_option." 의 재고수량이 부족합니다.\\n\\n현재 재고수량 : " . number_format($it_stock_qty - $sum_qty) . " 개");

                }

            }</p>

<p>            // 예약 상품

            $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('예약상품과 일반상품은 같이 주문하실 수 없습니다.');</p>

<p> </p>

<p>            $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);

        }

    }</p>

<p>    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'));

}</p>

<p>

 

에서

 

</p>

<p>// 예약 상품

$sql = " select ct_reserve, ct_normal

              from {$g5['g5_shop_cart_table']}

              where od_id = '$tmp_cart_id'

              and it_id = '$it_id' ";</p>

<p>$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;</p>

<p>echo $check_reserve;

if ( $check_reserve && $check_normal ) alert('예약상품과 일반상품은 같이 주문하실 수 없습니다.');</p>

<p>

 

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

 

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

 

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

 

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

 

1번 돌고 끝나는거 같아요

 

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

 

뭐가 잘못된건가요? ㅠㅠ

 

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

 

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

답변 2개

채택된 답변
+20 포인트
Policia
5년 전

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

 

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

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

 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 4개

블랑숑
5년 전
해결했습니다! sql에서 sum으로 가져와서

그걸 다시 += 하면 되는거 같아요 ㅠㅠ

답변에 힌트를 얻었습니다 너무 감사합니다!
블랑숑
5년 전
아 해결된지 알았는데 마지막 관문이 있네요 ㅠㅠ

체크된게 아니라 장바구니에 있는거 전체를 불러오네요
P
Policia
5년 전
음 예약상품을 불러오는기준점을 잡아야할것같은데요
장바구니에서 예약상품은 무엇이며 예약상품을 구분하는 코드는 어떤것이고 또 체크한 장바구니 상품에서의 예약상품..? 전체적인 기능과 구조를 알수없으니 ㅠㅠ 조언을드리기가 곤란하네요
블랑숑
5년 전
새로운 질문글 올렸습니다

실례가 안된다면 확인 해주시면 너무 감사할게요 ㅠㅠ

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

프라푸치노K
$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 '
';
$check_reserve = $check_normal = 0;
$result = sql_query($sql);
while ($row=sql_fetch_array($result)){
print_r2($row);
echo '
';
           $check_reserve+= $row['ct_reserve'];
           $check_normal+= $row['ct_normal'];
       }
echo $check_normal;
echo $check_reserve;

echo '


';

exit;

 

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

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

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

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

블랑숑
5년 전
감사합니다 답변 너무너무 감사합니다

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

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

로그인