영카트 쿼리의 변수화와 관련하여 질문드립니다. 채택완료
slingshot
8년 전
조회 2,349
안녕하세요 sir회원님들
배송비를 구하는 함수중에 변수로 받고싶은 부분이 있는데 php를 잘몰라 질문드립니다
코드는 다음과 같습니다.
</p>
<p> for($i=0; $sc=sql_fetch_array($result); $i++) {
// 합계
// 상품별로 가격과 수량을 반복문처리 (price,qty)
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(ct_qty) as qty,
(select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id') as k_price
from {$g5['g5_shop_cart_table']}
where it_id = '{$sc['it_id']}'
and od_id = '$cart_id'
and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )
and ct_select = '$selected'";
$sum = sql_fetch($sql);</p>
<p>//배송비 =상품별 배송비 구하는 함수 호출(상품코드,가격,수량,카트id)
$send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id);</p>
<p> //상품별 배송비 > 0
if($send_cost > 0 )
$total_send_cost + = $send_cost</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p> </p>
<p> </p>
<p>
여기서 별칭으로 처리한 k_price 를 변수로 받아서
if($send_cost > 0 && $k_price ) 이런식으로 쓰고싶은데 어떻게해야하나요?
$sum['k_price']로 받았더니 기존에 k_price보다 조금더 금액이 가산되서 이해가 잘안가네요;
댓글을 작성하려면 로그인이 필요합니다.
답변 3개
채택된 답변
+20 포인트
답변에 대한 댓글 5개
s
slingshot
8년 전
�
플라이
8년 전
$k_price = $sum[' k_price']
이렇게 쓰시면 될듯 합니다.
이렇게 쓰시면 될듯 합니다.
s
slingshot
8년 전
플라이님 답변주셔서 정말 감사한데
[code]
for($i=0; $sc=sql_fetch_array($result); $i++) {
// 합계
// 상품별로 가격과 수량을 반복문처리 (price,qty)
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(ct_qty) as qty,
(select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id') as k_price
from {$g5['g5_shop_cart_table']}
where it_id = '{$sc['it_id']}'
and od_id = '$cart_id'
and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )
and ct_select = '$selected'";
$k_sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id' ";
$sum = sql_fetch($sql);
//배송비 =상품별 배송비 구하는 함수 호출(상품코드,가격,수량,카트id)
$send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id);
$k_price = $sum['k_price'];
//상품별 배송비 > 0
if($send_cost > 0 && $k_price > 30000)
$total_send_cost = 0;
if($default['de_send_cost_case'] == '차등' && $send_cost == -1) {
$total_price += $sum['price'];
$diff++;
}
}
[/code]
위와같이 처리하게되면 상품별 배송비 > 0 조건에 들어오질않는걸 보니
k_price 변수처리에 문제가 있는건가요? 답변부탁드립니다.
[code]
for($i=0; $sc=sql_fetch_array($result); $i++) {
// 합계
// 상품별로 가격과 수량을 반복문처리 (price,qty)
$sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
SUM(ct_qty) as qty,
(select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id') as k_price
from {$g5['g5_shop_cart_table']}
where it_id = '{$sc['it_id']}'
and od_id = '$cart_id'
and ct_status IN ( '쇼핑', '주문', '입금', '준비', '배송', '완료' )
and ct_select = '$selected'";
$k_sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id' ";
$sum = sql_fetch($sql);
//배송비 =상품별 배송비 구하는 함수 호출(상품코드,가격,수량,카트id)
$send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id);
$k_price = $sum['k_price'];
//상품별 배송비 > 0
if($send_cost > 0 && $k_price > 30000)
$total_send_cost = 0;
if($default['de_send_cost_case'] == '차등' && $send_cost == -1) {
$total_price += $sum['price'];
$diff++;
}
}
[/code]
위와같이 처리하게되면 상품별 배송비 > 0 조건에 들어오질않는걸 보니
k_price 변수처리에 문제가 있는건가요? 답변부탁드립니다.
�
플라이
8년 전
if($send_cost > 0 && $k_price > 30000)
if($send_cost > 0 || $k_price > 30000) 이렇게 변경해 보세요 두개가 true가 나야 가능해서 그런겁니다.
if($send_cost > 0 || $k_price > 30000) 이렇게 변경해 보세요 두개가 true가 나야 가능해서 그런겁니다.
s
slingshot
8년 전
답변주셔서 감사합니다. 모든분들이 도움주셔서 결국 끝냈네요
댓글을 작성하려면 로그인이 필요합니다.
답변에 대한 댓글 1개
s
slingshot
8년 전
답변주셔서 감사합니다. 모든분들이 도움주셔서 결국 끝냈네요
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
(select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) from {$g5['g5_shop_cart_table']} where it_id LIKE 'K%' AND od_id = '$cart_id') as k_price
[/code]
sql중에 서브쿼리문에 위에해당 내용은 상품코드가 K로 시작하는 상품들의 총합을 구합니다.
이 총합을 구해서 k로 시작하는 상품의 총가격이 3만원이넘을시에 해당 k상품들의 배송비는
무료로 처리하기 위함입니다.