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);
}
위와 같은 방식으로 처리하셔야 합니다.
(정확한 작동여부는 확인하시면서 수정하시기바랍니다.)
!-->
답변을 작성하시기 전에 로그인 해주세요.