select문 selected 작업오류 와 배열값추출 문제등 질문몇가지 드립니다.

매출이 오르면 내리는 수수료! 지금 수수료센터에서 전자결제(PG)수수료 비교견적 신청해 보세요!
select문 selected 작업오류 와 배열값추출 문제등 질문몇가지 드립니다.

QA

select문 selected 작업오류 와 배열값추출 문제등 질문몇가지 드립니다.

본문

택배사 선택시 택배사 요금표가 출력되며 옆에 input창 (수량)만 적으면 요금*수량이 체크되어 배송비에 등록되는 작업을 하고있습니다.

 

첫번째 문제는 select 박스를 선택시 출력되는 택배사가 모두 selected값을 가지고 출력이 됩니다.
선택클릭했을때... selected가 체크가 되어야 하는게 맞는데요.. 이문제가 해결이 안되네요.ㅠ
$dv_row['dv_no'] = [0,1,2,3,4] 등록되어 있는 값 입니다.

 

두번째로 for문에서 ['dv_no'](배송고유번호)  $dv_set[]= $dv_row['dv_no']; 을 배열로 담아 select박스에서 선택 후 수량입력하여 등록하면
$dv_set[1]의 $dv['dv_name'](택배사명) 로만 등록되는 문제가 발생됩니다. select박스에서 선택한 택배사명이 등록되어야하는데요..ㅠ

 

세번째로 작업중인 아래의 코드를 보시면 택배사가 늘어나면 늘어날수록 <tbody>와<script>숫자와 변수만다른 같은 코드들이 거의 복사 붙여넣기 식으로 증가되어야 하는 것 같습니다.
코드를 줄일 수있는 방법이 있다면 조언부탁드리겠습니다. 



<tbody>
<tr>
    <th scope="row"><label for="it_sc_method">택배사 선택</label></th>
    <td>
        <select name="it_sc_method" id="dv_sc_method">
            <?php
            $dv_sql = "select * from {$g5['delivery_table']} order by `dv_no` ASC";
            $dv_result = sql_query($dv_sql);
            for ($i=0; $dv_row=sql_fetch_array($dv_result); $i++) {
                echo "<option value=\"".$i."\"".get_selected($dv_row['dv_no'], $i).">".$dv_row['dv_name']."</option>\n";
                $dv_set[]= $dv_row['dv_no'];
            }
            ?>
        </select>
    </td>
</tr>
</tbody>
<?php if(isset($dv_set[0])){
    $dv_sql1 = "select * from {$g5['delivery_table']} where dv_no = '{$dv_set[0]}' ";
    $dv_result1 = sql_query($dv_sql1);
    $dv = sql_fetch_array($dv_result1);
    ?>
    <tbody id="dv_con_type">
    <tr>
        <th scope="row"><?php echo $dv['dv_type1']; ?>(<?php echo $dv['dv_price1']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price1" id="it_dv_price1" value="<?php echo $dv['dv_price1']; ?>">
            <input type="text" name="it_6" id="it_6" value="<?php echo get_text($it['it_6']) ?>" class="frm_input" onkeyup="call();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type2']; ?>(<?php echo $dv['dv_price2']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price2" id="it_dv_price2" value="<?php echo $dv['dv_price2']; ?>">
            <input type="text" name="it_7" id="it_7" value="<?php echo get_text($it['it_7']) ?>" class="frm_input" onkeyup="call();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type3']; ?>(<?php echo $dv['dv_price3']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price3" id="it_dv_price3" value="<?php echo $dv['dv_price3']; ?>">
            <input type="text" name="it_8" id="it_8" value="<?php echo get_text($it['it_8']) ?>" class="frm_input" onkeyup="call();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type4']; ?>(<?php echo $dv['dv_price4']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price4" id="it_dv_price4" value="<?php echo $dv['dv_price4']; ?>">
            <input type="text" name="it_9" id="it_9" value="<?php echo get_text($it['it_9']) ?>" class="frm_input" onkeyup="call();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type5']; ?>(<?php echo $dv['dv_price5']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price5" id="it_dv_price5" value="<?php echo $dv['dv_price5']; ?>">
            <input type="text" name="it_10" id="it_10" value="<?php echo get_text($it['it_10']) ?>" class="frm_input" onkeyup="call();" size="5">
        </td>
    </tr>
    </tbody>
<?php } ?>
<?php if(isset($dv_set[1])){
    $dv_sql2 = "select * from {$g5['delivery_table']} where dv_no = '{$dv_set[1]}' ";
    $dv_result2 = sql_query($dv_sql2);
    $dv = sql_fetch_array($dv_result2);
    ?>
    <tbody id="dv_con_type1">
    <tr>
        <th scope="row"><?php echo $dv['dv_type1']; ?>(<?php echo $dv['dv_price1']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price1" id="it_dv_price1_1" value="<?php echo $dv['dv_price1']; ?>">
            <input type="text" name="it_6" id="it_6_1" value="<?php echo get_text($it['it_6']) ?>" class="frm_input" onkeyup="call1();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type2']; ?>(<?php echo $dv['dv_price2']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price2" id="it_dv_price2_1" value="<?php echo $dv['dv_price2']; ?>">
            <input type="text" name="it_7" id="it_7_1" value="<?php echo get_text($it['it_7']) ?>" class="frm_input" onkeyup="call1();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type3']; ?>(<?php echo $dv['dv_price3']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price3" id="it_dv_price3_1" value="<?php echo $dv['dv_price3']; ?>">
            <input type="text" name="it_8" id="it_8_1" value="<?php echo get_text($it['it_8']) ?>" class="frm_input" onkeyup="call1();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type4']; ?>(<?php echo $dv['dv_price4']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price4" id="it_dv_price4_1" value="<?php echo $dv['dv_price4']; ?>">
            <input type="text" name="it_9" id="it_9_1" value="<?php echo get_text($it['it_9']) ?>" class="frm_input" onkeyup="call1();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv['dv_type5']; ?>(<?php echo $dv['dv_price5']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price5" id="it_dv_price5_1" value="<?php echo $dv['dv_price5']; ?>">
            <input type="text" name="it_10" id="it_10_1" value="<?php echo get_text($it['it_10']) ?>" class="frm_input" onkeyup="call1();" size="5">
        </td>
    </tr>
    </tbody>
<?php } ?>
<?php if(isset($dv_set[2])){
    $dv_sql3 = "select * from {$g5['delivery_table']} where dv_no = '{$dv_set[2]}' ";
    $dv_result3 = sql_query($dv_sql3);
    $dv3 = sql_fetch_array($dv_result3);
    ?>
    <tbody id="dv_con_type2">
    <tr>
        <th scope="row"><?php echo $dv3['dv_type1']; ?>(<?php echo $dv3['dv_price1']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price1" id="it_dv_price1_2" value="<?php echo $dv3['dv_price1']; ?>">
            <input type="text" name="it_6" id="it_6_2" value="<?php echo get_text($it['it_6']) ?>" class="frm_input" onkeyup="call2();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv3['dv_type2']; ?>(<?php echo $dv3['dv_price2']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price2" id="it_dv_price2_2" value="<?php echo $dv3['dv_price2']; ?>">
            <input type="text" name="it_7" id="it_7_2" value="<?php echo get_text($it['it_7']) ?>" class="frm_input" onkeyup="call2();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv3['dv_type3']; ?>(<?php echo $dv3['dv_price3']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price3" id="it_dv_price3_2" value="<?php echo $dv3['dv_price3']; ?>">
            <input type="text" name="it_8" id="it_8_2" value="<?php echo get_text($it['it_8']) ?>" class="frm_input" onkeyup="call2();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv3['dv_type4']; ?>(<?php echo $dv3['dv_price4']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price4" id="it_dv_price4_2" value="<?php echo $dv3['dv_price4']; ?>">
            <input type="text" name="it_9" id="it_9_2" value="<?php echo get_text($it['it_9']) ?>" class="frm_input" onkeyup="call2();">
        </td>
    </tr>
    <tr>
        <th scope="row"><?php echo $dv3['dv_type5']; ?>(<?php echo $dv3['dv_price5']; ?> 원)</th>
        <td class="td_extra">
            <input type="hidden" name="it_dv_price5" id="it_dv_price5_2" value="<?php echo $dv3['dv_price5']; ?>">
            <input type="text" name="it_10" id="it_10_2" value="<?php echo get_text($it['it_10']) ?>" class="frm_input" onkeyup="call2();" size="5">
        </td>
    </tr>
    </tbody>
<?php } ?>
<tfoot>
<tr>
    <td>
        <input type="text" name="it_5" value="<?php echo get_text($dv['dv_name']) ?>" id="it_5" class="frm_input">
        <input type="text" name="it_sc_price" value="<?php echo $it['it_sc_price']; ?>" id="it_sc_price" class="frm_input" size="8"> 원
    </td>
</tr>
</tfoot>
<script>
    function call() {
        if(document.getElementById('it_6').value){
            document.getElementById('it_7').value ='';
            document.getElementById('it_8').value ='';
            document.getElementById('it_9').value ='';
            document.getElementById('it_10').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_6').value) * parseInt(document.getElementById('it_dv_price1').value);
            return;
        }
        if(document.getElementById('it_7').value){
            document.getElementById('it_6').value ='';
            document.getElementById('it_8').value ='';
            document.getElementById('it_9').value ='';
            document.getElementById('it_10').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_7').value) * parseInt(document.getElementById('it_dv_price2').value);
            return;
        }
        if(document.getElementById('it_8').value){
            document.getElementById('it_7').value ='';
            document.getElementById('it_6').value ='';
            document.getElementById('it_9').value ='';
            document.getElementById('it_10').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_8').value) * parseInt(document.getElementById('it_dv_price3').value);
            return;
        }
        if(document.getElementById('it_9').value){
            document.getElementById('it_7').value ='';
            document.getElementById('it_8').value ='';
            document.getElementById('it_6').value ='';
            document.getElementById('it_10').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_9').value) * parseInt(document.getElementById('it_dv_price4').value);
            return;
        }
        if(document.getElementById('it_10').value){
            document.getElementById('it_7').value ='';
            document.getElementById('it_8').value ='';
            document.getElementById('it_9').value ='';
            document.getElementById('it_6').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_10').value) * parseInt(document.getElementById('it_dv_price5').value);
            return;
        }
    }
    function call1() {
        if(document.getElementById('it_6_1').value){
            document.getElementById('it_7_1').value ='';
            document.getElementById('it_8_1').value ='';
            document.getElementById('it_9_1').value ='';
            document.getElementById('it_10_1').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_6_1').value) * parseInt(document.getElementById('it_dv_price1_1').value);
            return;
        }
        if(document.getElementById('it_7_1').value){
            document.getElementById('it_6_1').value ='';
            document.getElementById('it_8_1').value ='';
            document.getElementById('it_9_1').value ='';
            document.getElementById('it_10_1').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_7_1').value) * parseInt(document.getElementById('it_dv_price2_1').value);
            return;
        }
        if(document.getElementById('it_8_1').value){
            document.getElementById('it_7_1').value ='';
            document.getElementById('it_6_1').value ='';
            document.getElementById('it_9_1').value ='';
            document.getElementById('it_10_1').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_8_1').value) * parseInt(document.getElementById('it_dv_price3_1').value);
            return;
        }
        if(document.getElementById('it_9_1').value){
            document.getElementById('it_7_1').value ='';
            document.getElementById('it_8_1').value ='';
            document.getElementById('it_6_1').value ='';
            document.getElementById('it_10_1').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_9_1').value) * parseInt(document.getElementById('it_dv_price4_1').value);
            return;
        }
        if(document.getElementById('it_10_1').value){
            document.getElementById('it_7_1').value ='';
            document.getElementById('it_8_1').value ='';
            document.getElementById('it_9_1').value ='';
            document.getElementById('it_6_1').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_10_1').value) * parseInt(document.getElementById('it_dv_price5_1').value);
            return;
        }
    }
    function call2() {
        if(document.getElementById('it_6_2').value){
            document.getElementById('it_7_2').value ='';
            document.getElementById('it_8_2').value ='';
            document.getElementById('it_9_2').value ='';
            document.getElementById('it_10_2').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_6_2').value) * parseInt(document.getElementById('it_dv_price1_2').value);
            return;
        }
        if(document.getElementById('it_7_2').value){
            document.getElementById('it_6_2').value ='';
            document.getElementById('it_8_2').value ='';
            document.getElementById('it_9_2').value ='';
            document.getElementById('it_10_2').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_7_2').value) * parseInt(document.getElementById('it_dv_price2_2').value);
            return;
        }
        if(document.getElementById('it_8_2').value){
            document.getElementById('it_7_2').value ='';
            document.getElementById('it_6_2').value ='';
            document.getElementById('it_9_2').value ='';
            document.getElementById('it_10_2').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_8_2').value) * parseInt(document.getElementById('it_dv_price3_2').value);
            return;
        }
        if(document.getElementById('it_9_2').value){
            document.getElementById('it_7_2').value ='';
            document.getElementById('it_8_2').value ='';
            document.getElementById('it_6_2').value ='';
            document.getElementById('it_10_2').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_9_2').value) * parseInt(document.getElementById('it_dv_price4_2').value);
            return;
        }
        if(document.getElementById('it_10_2').value){
            document.getElementById('it_7_2').value ='';
            document.getElementById('it_8_2').value ='';
            document.getElementById('it_9_2').value ='';
            document.getElementById('it_6_2').value ='';
            document.getElementById('it_sc_price').value =parseInt(document.getElementById('it_10_2').value) * parseInt(document.getElementById('it_dv_price5_2').value);
            return;
        }
    }
    $(function() {
        <?php
        switch($dv_row['dv_sc_method']) {
            case 0:
                echo '$("#dv_con_type").show();'.PHP_EOL;
                echo '$("#dv_con_type1").hide();'.PHP_EOL;
                echo '$("#dv_con_type2").hide();'.PHP_EOL;
                break;
            case 1:
                echo '$("#dv_con_type").hide();'.PHP_EOL;
                echo '$("#dv_con_type1").show();'.PHP_EOL;
                echo '$("#dv_con_type2").hide();'.PHP_EOL;
                break;
            default:
                echo '$("#dv_con_type").hide();'.PHP_EOL;
                echo '$("#dv_con_type1").hide();'.PHP_EOL;
                echo '$("#dv_con_type2").hide();'.PHP_EOL;
                break;
        }
        ?>
        $("#dv_sc_method").change(function() {
            var type = $(this).val();
            switch(type) {
                case "0":
                    $("#dv_con_type").show();
                    $("#dv_con_type1").hide();
                    $("#dv_con_type2").hide();
                    break;
                case "1":
                    $("#dv_con_type").hide();
                    $("#dv_con_type1").show();
                    $("#dv_con_type2").hide();
                    break;
                default:
                    $("#dv_con_type").hide();
                    $("#dv_con_type1").hide();
                    $("#dv_con_type2").hide();
                    break;
            }
        });
    });
</script>

이 질문에 댓글 쓰기 :

답변 1


            <?php
            $dv_sql = "select * from {$g5['delivery_table']} order by `dv_no` ASC";
            $dv_result = sql_query($dv_sql);
            for ($i=0; $dv_row=sql_fetch_array($dv_result); $i++) {
                echo "<option value=\"".$dv_row['dv_no']."\"".get_selected($it_sc_method,$dv_row['dv_no']).">".$dv_row['dv_name']."</option>\n";
                $dv_set[]= $dv_row['dv_no'];
            }
            ?>
답변을 작성하시기 전에 로그인 해주세요.
전체 0
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT