메뉴 건너뛰기

프로그램언어

조회 수 6085 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

HTML 부분

<form id="fm" name="fm" method="get" action="list.php">
    <table border="0" cellpadding="0" cellspacing="0">
        <tbody><tr>
            <td>
                <select id="sel1" name="sel1" onchange="update_cate1()" style="width:140px;"><!--1차-->
                    <option value="">--메이커--</option>
                <!--1단은 db에서 목록 받아와서 뿌려줌-->
                <!--?
                                while($sbvrow=mysql_fetch_array($sbvlist))
                {
                echo "<option value='$sbvrow[category]'---->$sbvrow[catnm]";
 
                }
                ?>
 
 
                </select>
                 
            </td>
            <td id="catetd2" name="catetd2" style="padding-left:3px;">
<!--sel2 셀렉트박스 들어옴-->
            </td>
        </tr>
        <tr>
            <td id="catetd3" name="catetd3" style="padding-top:5px;">
<!--sel3 셀렉트박스 들어옴-->
            </td>
 
            <td id="catetd4" name="catetd4" style="padding-top:5px;padding-left:3px;">
<!--sel4 셀렉트박스 들어옴-->
            </td>
        </tr>
    </tbody></table>
</form>

JS 부분

//-----------------------1단-----------------------------    
    function update_cate1()
    {
        var cateval = $('#sel1').attr('value');
        $.get('get_cate.php?cateval=' + cateval,show_cates1);
         
    }
 
    function show_cates1(res){
    $('#catetd2').html(res);
    $('#catetd3').html("");
    $('#catetd4').html("");
 
    }
//-----------------------1단-----------------------------
//-----------------------2단-----------------------------
    function update_cate2()
    {
        var cateval = $('#sel2').attr('value');
        $.get('get_cate2.php?cateval=' + cateval,show_cates2);
         
    }
    function show_cates2(res2){
    $('#catetd3').html(res2);
    $('#catetd4').html("");
 
    }
//-----------------------2단-----------------------------
//-----------------------3단-----------------------------
function update_cate3()
    {
        var cateval = $('#sel3').attr('value');
        $.get('get_cate3.php?cateval=' + cateval,show_cates3);
    }
    function show_cates3(res3){
    $('#catetd4').html(res3);
    }
//-----------------------3단-----------------------------


get_cate1.php, get_cate2.php, get_cate3.php의 소


$sbvconn=mysql_connect($db_host,$db_user,$db_pass); 
    mysql_select_db($db_name, $sbvconn);
     
    //카테고리 구분자 퍼옴  
    //  ex)카테고리이름
    //  제조사 Acrua -> 년도 2011 -> 모델명 hyhf05 -> 기타 추가품 HKI005
    //  001 -> 001002 -> 001002001 -> 001002001004
 
    $cateval = $_REQUEST['cateval'];
    $cateval_len=strlen($cateval);
     
    $sbvsql = "셀렉트 박스에 넣을 목록 쿼리";
//ex)"SELECT * FROM category where CHARACTER_LENGTH(category)=9 and LEFT(category,6)='".$cateval."' order by sno";
    $sbvlist=mysql_query($sbvsql, $sbvconn);
    $sbvnum = mysql_num_rows($sbvlist);
    $sbvnum=$sbvnum+1;
//결과 없을경우 셀박스를 띄우기 않음
if($sbvnum>1){
//아래 셀렉트 박스 id 와 네임을 2단(get_cate2.php)의 경우 sel3 3단(get_cate3.php)의 경우 sel4
echo "<select id="sel2" name="sel2" style="width:140px" onchange="update_cate2()">";
    echo "<option value="\"\"">--년도--</option>";
    while($sbvrow=mysql_fetch_array($sbvlist)){
    echo"<option value="$sbvrow[category]">$sbvrow[catnm]</option>";
    $i++;
    }
    echo "</select>";
}else{
 
}

셀렉트 박스 목록을 클릭시 마다 해당 카테고리의 목록을 db에서 목록을 불러 와서 추가된 셀렉트박스에 띄워줍니다.


활용하기에 따라 무한 반복 가능합니다

DB에 넣을 카테고리의 항목은 번호,카테고리구분자,카테고리이름 필드의 형태가 좋구여.

 

해당예제는 4단 카테고리입니다.



  1. PHP 소스코드 인코딩(암호화)하기

    Date2018.07.19 Views6645
    Read More
  2. DB 연동 4단 셀렉트 박스

    Date2018.09.28 Views6085
    Read More
  3. fcm 푸시 알림 php 테스트

    Date2018.07.19 Views6048
    Read More
  4. 쿠폰번호 발행 업데이트판. (간단한 클래스화[PHP4 기준] 등...)

    Date2018.07.19 Views6041
    Read More
  5. PHP 파일크기 단위 붙이기 (용량 변환) file size conversion source code

    Date2018.07.04 Views5793
    Read More
  6. 키를 이용한 암호화/복호화 함수입니다.

    Date2018.07.24 Views5741
    Read More
  7. gcm 푸시 알림 php 테스트

    Date2018.07.19 Views5582
    Read More
  8. PHP 특정 디렉토리에 있는 파일 갯수 구하기

    Date2018.07.19 Views5455
    Read More
  9. 방금 INSERT 했던 SQL 문의 PK(primary key)값 가져오기

    Date2018.07.04 Views5347
    Read More
  10. 이미지 땡겨와서 출력하기

    Date2018.09.28 Views5288
    Read More
  11. 날짜, 시간 포맷하기 (PHP)

    Date2018.07.04 Views5230
    Read More
  12. MySQL테이블의 내용을 엑셀파일(xls)로 다운로드 하기

    Date2018.07.24 Views4798
    Read More
  13. 게시판 내용 숨김 클릭시 내용 출력 [ 참고 ]

    Date2018.07.24 Views4767
    Read More
  14. PHP 랜덤확률 구하기

    Date2018.10.27 Views4763
    Read More
  15. 마우스 오버시 사진변환, 파일에러시 대체이미지 적용(소스일부)

    Date2018.07.24 Views4584
    Read More
  16. 웹서버조회 소스

    Date2018.07.24 Views4543
    Read More
  17. 날짜계산 몇일까지.. [ ex)4 일전 new 표시 ]

    Date2018.07.24 Views4523
    Read More
  18. PHP 랜덤 문자열 생성

    Date2018.10.27 Views4121
    Read More
  19. PHP eregi가 빠를까, strpos가 빠를까?

    Date2018.10.27 Views4091
    Read More
  20. PHP 휴대폰번호 짜르기 (preg_replace) "-" 넣기. 형식바꾸기

    Date2018.07.04 Views4057
    Read More
Board Pagination Prev 1 ... 5 6 7 8 9 10 11 12 13 14 ... 17 Next
/ 17

하단 정보를 입력할 수 있습니다

© k2s0o1d4e0s2i1g5n. All Rights Reserved