for구문 수정 부탁
본문
for($j=0; $j<1; $j++) {일때 $spl_price = 1000;
for($j=1; $j<2; $j++) {일때 $spl_price = 2000;
for($j=2; $j<3; $j++) {일때 $spl_price = 3000;
가격을 각각 다르게 고정되게 하려고합니다.
수정을 어떻게 해야될까요
<?php
} // for
} else {
for($i=0; $i<$subject_count; $i++) {
$spl_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['subject'][$i])));
$spl_val = explode(',', preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['supply'][$i]))));
$spl_count = count($spl_val);
for($j=0; $j<$spl_count; $j++) {
$spl = strip_tags(trim($spl_val[$j]));
if($spl_subject && strlen($spl)) {
$spl_id = $spl_subject.chr(30).$spl;
$spl_price = 1000;
$spl_stock_qty = 9999;
$spl_noti_qty = 100;
$spl_use = 1;
// 기존에 설정된 값이 있는지 체크
if($_POST['w'] == 'u') {
$sql = " select io_price, io_stock_qty, io_noti_qty, io_use
from {$g5['g5_shop_item_option_table']}
where it_id = '{$_POST['it_id']}'
and io_id = '$spl_id'
and io_type = '1' ";
$row = sql_fetch($sql);
if($row) {
$spl_price = (int)$row['io_price'];
$spl_stock_qty = (int)$row['io_stock_qty'];
$spl_noti_qty = (int)$row['io_noti_qty'];
$spl_use = (int)$row['io_use'];
}
}
?>
답변 2
<?php
for($i=0; $i<$subject_count; $i++) {
$spl_subject = preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['subject'][$i])));
$spl_val = explode(',', preg_replace(G5_OPTION_ID_FILTER, '', trim(stripslashes($_POST['supply'][$i]))));
$spl_count = count($spl_val);
for($j=0; $j<$spl_count; $j++) {
$spl = strip_tags(trim($spl_val[$j]));
if($spl_subject && strlen($spl)) {
$spl_id = $spl_subject.chr(30).$spl;
switch ($j){
case '0':
$spl_price = 1000;
break;
case '1':
$spl_price = 2000;
break;
case '2':
$spl_price = 3000;
break;
default:
$spl_price = 1000;
}
$spl_stock_qty = 9999;
$spl_noti_qty = 100;
$spl_use = 1;
// 기존에 설정된 값이 있는지 체크
if($_POST['w'] == 'u') {
$sql = " select io_price, io_stock_qty, io_noti_qty, io_use
from {$g5['g5_shop_item_option_table']}
where it_id = '{$_POST['it_id']}'
and io_id = '$spl_id'
and io_type = '1' ";
$row = sql_fetch($sql);
if($row) {
$spl_price = (int)$row['io_price'];
$spl_stock_qty = (int)$row['io_stock_qty'];
$spl_noti_qty = (int)$row['io_noti_qty'];
$spl_use = (int)$row['io_use'];
}
}
?>
$spl_price = 1000;
->
if ($j == 0)
$spl_price = 1000;
else if ($j == 1)
$spl_price = 2000;
else if ($j == 2)
$spl_price = 3000;