라디오버튼값 불러오기

라디오버튼값 불러오기

QA

라디오버튼값 불러오기

답변 2

본문

쓰기 페이지


<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']) ?> 원

쓰기페이지


<?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>
    <?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>

<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 $wr_1_txt; ?><br>
인원 : <?php echo $view['wr_2']; ?> 명<br>
금액 : <?php echo number_format($view['wr_1'] * $view['wr_2']) ?> 원


이게 맞나요???
잘안되네요 ㅠ

DB 를 사용하지 않는 폼서브밋 값에 의한 단순 테스트 확인용 싱글페이지 예제 입니다.
확인 후 필요한 부분이 사용되면 될것 같습니다.


<?php
$write = $_POST;
if (isset($write['wr_1']) == false) {
    $write['wr_1'] = '';
}
if (isset($write['wr_2']) == false) {
    $write['wr_2'] = '';
}
$view = $write;

$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']];
}
?>

<form method="post">
<div class="write_div">
    <label>코스</label>
    <?php
    $outs = '';
    foreach ($wr_1_map as $k => $v) {
        $chkd = '';
        if ($write['wr_1'] == $k) {
            $chkd = ' checked="checked"';
        }
        $outs .= '<label><input type="radio" name="wr_1" itemname="wr_1" value="' . $k . '"' . $chkd . ' label="' . $v . '" required /> ' . $v . '</label>' . PHP_EOL;
    }
    echo $outs;
    ?>
 </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>

<input type="submit">
</form>

코스 : <?php echo $wr_1_txt; ?><br>
인원 :  <?php echo (int)$view['wr_2']; ?> 명<br>
금액 : <?php echo number_format((int)$view['wr_1'] * (int)$view['wr_2']) ?> 원

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