라디오버튼값 불러오기
본문
쓰기 페이지
<div class="write_div">
<label>코스</label>
<input type="radio" name="wr_1" itemname="wr_1" value="10000" <?php if($wr_1 == "체험1") { echo "checked=\"checked\""; } ?> label="체험1" required/> 체험1
<input type="radio" name="wr_1" itemname="wr_1" value="20000" <?php if($wr_1 == "체험2") { echo "checked=\"checked\""; } ?> label="체험2" required/> 체험2
<input type="radio" name="wr_1" itemname="wr_1" value="30000" <?php if($wr_1 == "체험3") { echo "checked=\"checked\""; } ?> label="체험3" required/> 체험3
</div>
<div class="write_div">
<select name="wr_2" id="wr_2" required>
<option value="">인원수</option>
<option value="1"<?php echo ($write['wr_2'] == "1명") ? " selected" : "";?>>1명</option>
<option value="2"<?php echo ($write['wr_2'] == "2명") ? " selected" : "";?>>2명</option>
<option value="3"<?php echo ($write['wr_2'] == "3명") ? " selected" : "";?>>3명</option>
</select>
</div>
보기 페이지
코스 : <?php echo $view['wr_1']; ?><br>
인원 : <?php echo $view['wr_2']; ?> 명<br>
금액 : <?php echo number_format($view['wr_1'] * $view['wr_2']) ?> 원
위와 같이 필드값 두가지를 보기페이지 금액부분 에서 곱하기로 처리하였습니다.
보기페이지에 숫자로도 출력하고, 각각 문자로도 출력하는 방법이 있나요?
쓰기페이지에서 "체험2 / 인원3명" 으로 선택했을때
보기페이지 예시
-----------------
코스 : 체험2
인원 : 3 명
금액 : 60,000 원
-----------------
!-->!-->
답변 2
<input type="radio" name="wr_1" itemname="wr_1" value="체험1:10000"~~~
~~~
view페이지
list($tit,$price) = explode(':',$view['wr_1']);
$tot_price = number_format($price * $view['wr_2']);
코스 : <?php echo $title?>
금액 : <?php echo $tot_price?> 원
<?php
$wr_1_map = ['10000' => '체험1', '20000' => '체험2', '30000' => '체험3'];
...
$wr_1_txt = 'N/A';
if (empty($view['wr_1']) == false && isset($wr_1_map[$view['wr_1']]) == true) {
$wr_1_txt = $wr_1_map[$view['wr_1']];
}
...
?>
...
<div class="write_div">
<label>코스</label>
<!--
<input type="radio" name="wr_1" itemname="wr_1" value="10000" <?php if($write['wr_1'] == "체험1") { echo "checked=\"checked\""; } ?> label="체험1" required/> 체험1
<input type="radio" name="wr_1" itemname="wr_1" value="20000" <?php if($write['wr_1'] == "체험2") { echo "checked=\"checked\""; } ?> label="체험2" required/> 체험2
<input type="radio" name="wr_1" itemname="wr_1" value="30000" <?php if($write['wr_1'] == "체험3") { echo "checked=\"checked\""; } ?> label="체험3" required/> 체험3
-->
<?php
$outs = '';
foreach ($wr_1_map as $k => $v) {
$chkd = '';
if ($write['wr_1'] == $k) {
$chkd = ' checked="checked"';
}
$outs .= '<input type="radio" name="wr_1" itemname="wr_1" value="10000"' . $chkd . ' label="' . $v . '" required /> ' . $v . PHP_EOL;
}
echo $outs;
?>
</div>
...
코스 : <?php echo $wr_1_txt; ?><br>
인원 : <?php echo $view['wr_2']; ?> 명<br>
금액 : <?php echo number_format($view['wr_1'] * $view['wr_2']) ?> 원
답변을 작성하시기 전에 로그인 해주세요.