조건문 좀 봐주세요 ㅠㅠ

조건문 좀 봐주세요 ㅠㅠ

QA

조건문 좀 봐주세요 ㅠㅠ

본문


 
if ($_POST['act_button'] == "철회") {
    for ($i=0; $i<count($_POST['chk']); $i++) {
        // 실제 번호를 넘김
        $k = $_POST['chk'][$i];
        $it_id = (int) $_POST['it_id'][$k];
        $ct_status = $_POST['ct_status2'][$k];
        $ct_status2 = '';
            
        $sql = " update {$g5['g5_shop_cart_table']}
                   set ct_status = '$ct_status',
                       ct_status2 = '$ct_status2'
                       where od_id = '$od_id'
                        and it_id = '$it_id' ";
        sql_query($sql);
    }
    $sql = " select ct_status
                    from {$g5['g5_shop_cart_table']}
                    where od_id = '$od_id' ";
    $result = sql_query($sql);
    $value = '';
    while ($row=sql_fetch_array($result)) {
        $value .= (($value)? ',' : '').$row['ct_status'];
    }
    $value2 = array('교환신청','교환중','교환완료','반품신청','반품중','반품완료');
    if (strpos($value, $value2) == false) {
        $od_return_status = '';
        $od_status = $ct_status;
        $od_return_memo = '';
 
    $sql2 = " update {$g5['g5_shop_order_table']}
                set od_return_memo = '$od_return_memo',
                    od_return_status = '$od_return_status',
                    od_status = '$od_status'
                    where od_id = '$od_id' ";
    sql_query($sql2);
 
    }
}

 

이런걸 만들었는데요

 

철회버튼을 누를 시 cart_table에 업데이트 하는 것까진 정상적으로 되구요

 

뒤쪽의 order_table 쪽이 문젠데

 

    $sql = " select ct_status
                    from {$g5['g5_shop_cart_table']}
                    where od_id = '$od_id' ";
    $result = sql_query($sql);

    $value = '';
    while ($row=sql_fetch_array($result)) {
        $value .= (($value)? ',' : '').$row['ct_status'];
    }

    $value2 = array('교환신청','교환중','교환완료','반품신청','반품중','반품완료');

    if (strpos($value, $value2) == false) {
        $od_return_status = '';
        $od_status = $ct_status;
        $od_return_memo = '';
         $sql2 = " update {$g5['g5_shop_order_table']}
                    set od_return_memo = '$od_return_memo',
                        od_return_status = '$od_return_status',
                        od_status = '$od_status'
                        where od_id = '$od_id' ";
        sql_query($sql2);
    }  

 

이 부분이 해당 od_id의 ct_status 부분을 가져와서

 

value2에 해당하는 부분이 없을 시

 

        $od_return_status = '';
        $od_status = $ct_status;
        $od_return_memo = '';

 

이렇게 해서 DB 업데이트 해주는건데요

 

value2에 해당하는게 있어도 바뀌네요

 

뭐가 잘못된건가요?

 

이 질문에 댓글 쓰기 :

답변 1

$value2 = array('교환신청','교환중','교환완료','반품신청','반품중','반품완료');

배열 선언하셨으면 if (strpos($value, $value2)  이문구 이전에 배열을 loop해서 체크하셔야 합니다

 

$value를 찍어보세요 $value값  확인해보셔야 겠습니다.
아래 코드로 하면 1 이라고 잘 찍힙니다.
이제 보니 위에서 value값을 교환신청,교환중,교환완료,반품신청
이런식으로 쌓으셨네요
코드를 새로 짜셔야겠습니다.

od_id 가 고유값인가요? 코드 새로 올려드려요



    $value2 = array('교환신청','교환중','교환완료','반품신청','반품중','반품완료');

    $sql = " select ct_status
                    from {$g5['g5_shop_cart_table']}
                    where od_id = '$od_id' ";
    $result = sql_query($sql);

    $value = '';
    while ($row=sql_fetch_array($result)) {

    if (!in_array($row['ct_status'], $value2)) { //없으면 업데이트

        $od_return_status = '';
        $od_status = $ct_status;
        $od_return_memo = '';
         $sql2 = " update {$g5['g5_shop_order_table']}
                    set od_return_memo = '$od_return_memo',
                        od_return_status = '$od_return_status',
                        od_status = '$od_status'
                        where od_id = '$od_id' ";
        sql_query($sql2);
    }  

    }

$row['ct_status']이 !in_array에 없으면 업데이트
아래것으로 해서 $row['ct_status']값 찍힌거 확인해보세용


    $value2 = array('교환신청','교환중','교환완료','반품신청','반품중','반품완료');

    $sql = " select ct_status
                    from {$g5['g5_shop_cart_table']}
                    where od_id = '$od_id' ";
    $result = sql_query($sql);

    $value = '';
    while ($row=sql_fetch_array($result)) {

    if (!in_array($row['ct_status'], $value2)) { //없으면 업데이트
        echo $row['ct_status'];
        $od_return_status = '';
        $od_status = $ct_status;
        $od_return_memo = '';
         $sql2 = " update {$g5['g5_shop_order_table']}
                    set od_return_memo = '$od_return_memo',
                        od_return_status = '$od_return_status',
                        od_status = '$od_status'
                        where od_id = '$od_id' ";
        sql_query($sql2);
    }  

    }

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

회원로그인

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