if문 문의
본문
if($row['it_soldout'] == '1' && $row['it_tel_inq'] !== '1') {
$discount_percent = "품절";
} else if($row['it_tel_inq'] == '1') {
$discount_percent = "문의";
} else {
$cost_value = $row['it_cust_price']; //원가
$discount_value = get_price($row); //할인가 = 판매가격
$discount_percent = (($cost_value - $discount_value) / $cost_value) * 100;
$discount_percent = round($discount_percent, 0)."%";
}
//echo "<div class=\"sct_cost\">\n";
echo "<span class=\"item_percent\">".$discount_percent."</span>";
위와 같은 소스에서
$cost_value가 0일때 0으로는 나눗셈을 못해 에러가 납니다.
0일때는
$discount_percent = (($cost_value - $discount_value) / $cost_value) * 100;
이부분을 건너띄고 싶습니다.
if문을 써야되는데 잘안먹어요 ㅜㅜ
고수님들 도와주세요~
!-->!-->
답변 2
if($cost_value !=0)
$discount_percent
= ((
$cost_value
-
$discount_value
) /
$cost_value
) * 100;
else
$discount_percent = 0;
$discount_percent = $cost_value > 0 ? (($cost_value - $discount_value) / $cost_value) * 100 : 0;
!-->
답변을 작성하시기 전에 로그인 해주세요.