영카트 쿼리의 변수화와 관련하여 질문드립니다.

영카트 쿼리의 변수화와 관련하여 질문드립니다.

QA

영카트 쿼리의 변수화와 관련하여 질문드립니다.

답변 3

본문

안녕하세요 sir회원님들

 

배송비를 구하는 함수중에 변수로 받고싶은 부분이 있는데 php를 잘몰라 질문드립니다

 

코드는 다음과 같습니다.


    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);
//배송비 =상품별 배송비 구하는 함수 호출(상품코드,가격,수량,카트id)
        $send_cost = get_item_sendcost($sc['it_id'], $sum['price'], $sum['qty'], $cart_id);
        //상품별 배송비 > 0 
        if($send_cost > 0  )
            $total_send_cost + = $send_cost
.
.
.
.
.
 
 

여기서 별칭으로 처리한 k_price 를 변수로 받아서

if($send_cost > 0 && $k_price )
            이런식으로 쓰고싶은데 어떻게해야하나요?

$sum['k_price']로 받았더니 기존에 k_price보다 조금더 금액이 가산되서 이해가 잘안가네요;

이 질문에 댓글 쓰기 :

답변 3

정확히 그렇게 하시고자 하는 목적이 불분명해서 답변을 드리기가 애매하네요


(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


sql중에 서브쿼리문에 위에해당 내용은 상품코드가 K로 시작하는 상품들의 총합을 구합니다.

이 총합을 구해서 k로 시작하는 상품의 총가격이 3만원이넘을시에 해당 k상품들의 배송비는
무료로 처리하기 위함입니다.

플라이님 답변주셔서 정말 감사한데


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++;
        }
    }


위와같이 처리하게되면 상품별 배송비 > 0 조건에 들어오질않는걸 보니
k_price 변수처리에 문제가 있는건가요? 답변부탁드립니다.

기존에 있는 쿼리에 추가로 서브쿼리로 추가하지마시고

어려우시면 단일 쿼리로 그 쿼리말고 새로 만들어서

해당 값만 가져와서

$send_cost 값과 비교하세요

굳이 어려운데 지금과 같이 한쿼리로 다 들고와야할 이유가있나요?

$sum['k_price']를 받아오는 쿼리를 하나 새로만드는것이 가독성에서도 편할겁니다.

댓글을 보니 $k_price 가 문자형인거 같은데 숫자 비교 부분이 조금 의심됩니다.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 12,369
© SIRSOFT
현재 페이지 제일 처음으로