array 포스트값 업데이트 문제

array 포스트값 업데이트 문제

QA

array 포스트값 업데이트 문제

본문

Array
(
    [od_id] => 2020092219161807
    [chkall] => 1
    [chk] => Array
        (
            [0] => 0
            [1] => 1
        )

    [it_id] => Array
        (
            [0] => 1598724050
            [1] => 1598950163
        )

    [ct_status] => Array
        (
            [0] => 입금
            [1] => 입금
        )

    [od_return_memo] => 46
    [act_button] => 교환신청
)

 

이렇게 포스트값이 넘어오고

 


$od_return_memo = strip_tags($od_return_memo);
if ($_POST['act_button'] == "교환신청") {
    $ct_status = '교환신청';
    $sql = " update {$g5['g5_shop_cart_table']}
                set ct_status = '$ct_status'
                    where od_id = '$od_id'
                    and it_id = '$it_id' ";
    sql_query($sql);
    $od_return_status = '1';
    $sql2 = " update {$g5['g5_shop_order_table']}
                set od_return_memo = '$od_return_memo',
                    od_return_status = '$od_return_status'
                    where od_id = '$od_id' ";
    sql_query($sql2);
}

 

이렇게 처리를 하려고 했는데요

 

g5_shop_order_table 부분은 상품이 몇 개든 od_id는 하나라 업데이트가 잘되는거 같은데

 

g5_shop_cart_table' 부분은 체크한 부분만 od_id 중에서 it_id로 구분해내어 set 해야 해서 어려움이 있습니다. 고수님들 도와주세요 ㅠㅠ

이 질문에 댓글 쓰기 :

답변 1

쇼핑카트는 od_id가 멀티로 작동되는구조라서

아래의 내용은 다음과 같이 수정해야 합니다.


<?php
...
$od_return_memo = strip_tags($od_return_memo);
if ($_POST['act_button'] == "교환신청") {
    $ct_status = '교환신청';
    if (is_array($it_id)) {  // 멀티값으로 넘어올때
        $cnt = count($it_id);
        for($i = 0; $i < $cnt; $i++) {
            
            $sql = " update {$g5['g5_shop_cart_table']}
                       set ct_status = '$ct_status'
                           where od_id = '$od_id'
                            and it_id = '$it_id[$i]' ";
            sql_query($sql);
         }
    }
    else {  // 단일값으로 넘어올때
        $sql = " update {$g5['g5_shop_cart_table']}
                    set ct_status = '$ct_status'
                        where od_id = '$od_id'
                        and it_id = '$it_id' ";
        sql_query($sql);
    }
    $od_return_status = '1';
    $sql2 = " update {$g5['g5_shop_order_table']}
                set od_return_memo = '$od_return_memo',
                    od_return_status = '$od_return_status'
                    where od_id = '$od_id' ";
    sql_query($sql2);
}

위와 같은 방식으로 처리하셔야 합니다.

(정확한 작동여부는 확인하시면서 수정하시기바랍니다.)

오 일단 업데이트는 잘 되는데요

보니까 하나만 체크해도 둘 다 바뀌네요

post가 넘어올 때

it_id는 체크하던 안하던 무조건 총 개수대로 넘어오구요

chk가 체크한 것만 넘어오게 되어 있어요

상품 2개 중에 1개만 체크하면

[chk] => Array
        (
            [0] => 0
        )

[it_id] => Array
        (
            [0] => 1598724050
            [1] => 1598950163
        )

일케요

그래서 그런거 같아요

for ($i=0; $i<count($_POST['chk']); $i++) {

// 실제 번호를 넘김
        $k = $_POST['chk'][$i];
        $it_id = (int) $_POST['it_id'][$k];
           
$sql = " update {$g5['g5_shop_cart_table']}
  set ct_status = '$ct_status'
  where od_id = '$od_id'
and it_id = '$it_id' ";
sql_query($sql);
    }

요렇게 해서 해결햇어용 ㅎㅎ


제가 적어드린건 개념적으로 배열로 넘어오는것과 아닌것의 차이의 일반적인 처리방버이라서요

체크사항이 있으면 추가해서 처리하시면됩니다.
잘해결하셨네요

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

회원로그인

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