<?php
include_once("$g5_path/config.php");
// 각 옵션에 대한 가격 정의
$prices = array(
"고양이" => 500, // wr_1
"토끼" => 1000, // wr_2
"사자" => 23000, // wr_3
"호랑이" => 100, // wr_4
"표범" => 5000, // wr_5
"기린" => 300 // wr_6
);
// 총 가격 초기화
$total_price = 0;
// $_POST 배열을 반복하여 체크된 항목의 가격 계산
foreach ($_POST as $key => $value) {
if (isset($prices[$value])) {
$total_price += $prices[$value];
}
}
// 총 가격을 콤마로 구분된 문자열로 변환
$formatted_total_price = number_format($total_price);
// 총 가격 출력
echo "Total Price: " . $formatted_total_price . "원";
?>
write.skin.php 에 이걸 사용하려고 하는데 왜 안되는지 모르겠어요 혹시 잘못된 부분이 있으면 알려주시면 감사합니다.
답변 5개 / 댓글 2개
채택된 답변
+20 포인트
Copy
<?php
include_once("$g5_path/config.php");
$_POST['animal'][]="고양이";
$_POST['animal'][]="사자";
$_POST['animal'][]="호랑이";
// 각 옵션에 대한 가격 정의
$prices = array(
"고양이" => 500, // wr_1
"토끼" => 1000, // wr_2
"사자" => 23000, // wr_3
"호랑이" => 100, // wr_4
"표범" => 5000, // wr_5
"기린" => 300 // wr_6
);
// 총 가격 초기화
$total_price = 0;
// $_POST 배열을 반복하여 체크된 항목의 가격 계산
foreach ($_POST['animal'] as $key => $value) {
if (isset($prices[$value])) {
$total_price += $prices[$value];
}
}
// 총 가격을 콤마로 구분된 문자열로 변환
$formatted_total_price = number_format($total_price);
// 총 가격 출력
echo "Total Price: " . $formatted_total_price . "원";
?>
앞에 POST변수가 어떻게 되어있는지 몰라서 임의로 추가했습니다.
답변을 작성하려면 로그인이 필요합니다.
include_once("$g5_path/config.php"); 이 위치가 맞는지 궁금합니다. 아니면 그냥 DB 접속 아이디 비번 넣고 해야 하는건지 잘 모르겠어서요