채택완료

shop/orderform.php 코드문의드립니다.

shop/orderform.sub.php 중 일부입니다.

 

            // 합계금액 계산
            $sql = " select SUM(IF(io_type = 1, (io_price * ct_qty), ((ct_price + io_price) * ct_qty))) as price,
                            SUM(ct_point * ct_qty) as point,
                            SUM(ct_qty) as qty
                        from {$g5['g5_shop_cart_table']}
                        where it_id = '{$row['it_id']}'
                          and od_id = '$s_cart_id' ";
            $sum = sql_fetch($sql);

 

위의 노란부분의 합계(price)가 item_option type=1인 경우에 

 (io_price * ct_qty) + ((ct_price + io_price) * ct_qty)))  인가요?

 아니면

 ((ct_price + io_price) * ct_qty))) 인가요?

|

답변 2개

채택된 답변
+20 포인트

mysql 의 if문은

 

다른 dbms의 decode와 동일하다고 보시면 됩니다.

 

if (조건, 참, 거짓)

 

그러면 위의 문장에서 수행될 내용은

Copy
SUM (

      IF(  io_type = 1

          , (io_price * ct_qty)

          , ((ct_price + io_price) * ct_qty)

       )

   ) as price,

 

이니

sum을 할때 레코드마다

 

io_type = 1 이면

   (io_price * ct_qty)

아니면

   ((ct_price + io_price) * ct_qty)

를 합산합니다.

 

 

 

알기쉬운 친절한 설명에 감사드립니다.^^

답변을 작성하려면 로그인이 필요합니다.