1. \n<? \/\/\n\/***********************************************\n** 功 能: php+mysql+javascript實現(xiàn)學(xué)院專業(yè)二級級聯(lián)下拉框\n** 數(shù)據(jù)庫:數(shù)據(jù)庫名( dms)、數(shù)據(jù)表( colleges、 majors)\n** 表 colleges中字段: college_id( id編號)、 name(學(xué)院名)\n** 表 majors中的字段: major_id( id編號)、 college_id(學(xué)院 ID)、 name(學(xué)院名)\n** version 1.0\n** 作 者: wu yaowen\n***********************************************\/\n\/\/****************** 連接選擇數(shù)據(jù)庫 ***************\n$link = mysql_connect(\"localhost\", \"root\", \"123456\")\n or die(\"Could not connect : \" . mysql_error());\nmysql_select_db(\"dms\") or die(\"Could not select database\");\n\/\/******************提取學(xué)院信息 ******************\n$queryCol = \"select * from colleges order by college_id \";\nmysql_query(\"SET NAMES 'gb2312'\");\n$result1 = mysql_query($queryCol) or die(\"Query failed : \" . mysql_error());\n$colleges = array();\nwhile( $row1 = mysql_fetch_array($result1) )\n{\n $colleges[] = $row1;\n}\n\/\/print_r ($forum_data);\nmysql_free_result($result1);\n\/\/**************獲取專業(yè)信息 ************** \n$queryMaj = \"select * from majors order by college_id desc\";\nmysql_query(\"SET NAMES 'gb2312'\");\nif( !($result2 = mysql_query($queryMaj)) )\n{\n die('Could not query t_city list');\n}\n$majors = array();\nwhile( $row2 = mysql_fetch_array($result2) )\n{\n $majors[] = $row2;\n}\nmysql_free_result($result2);\n?>\n\n

    国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

    Table of Contents
    Detailed explanation of the secondary linkage menu effect implemented by php mysql, mysql linkage
    Home Backend Development PHP Tutorial Detailed explanation of the effect of the secondary linkage menu implemented by php mysql, mysql linkage_PHP tutorial

    Detailed explanation of the effect of the secondary linkage menu implemented by php mysql, mysql linkage_PHP tutorial

    Jul 12, 2016 am 08:52 AM
    html code mysql php

    Detailed explanation of the secondary linkage menu effect implemented by php mysql, mysql linkage

    This article describes the secondary linkage menu effect implemented by php mysql. Share it with everyone for your reference, the details are as follows:

    <!--php+mysql二級聯(lián)動-->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>生成學(xué)院專業(yè)級聯(lián)下拉菜單測試 </title>
    </head>
    <body>
    <&#63; //
    /***********************************************
    ** 功 能: php+mysql+javascript實現(xiàn)學(xué)院專業(yè)二級級聯(lián)下拉框
    ** 數(shù)據(jù)庫:數(shù)據(jù)庫名( dms)、數(shù)據(jù)表( colleges、 majors)
    ** 表 colleges中字段: college_id( id編號)、 name(學(xué)院名)
    ** 表 majors中的字段: major_id( id編號)、 college_id(學(xué)院 ID)、 name(學(xué)院名)
    ** version 1.0
    ** 作 者: wu yaowen
    ***********************************************/
    //****************** 連接選擇數(shù)據(jù)庫 ***************
    $link = mysql_connect("localhost", "root", "123456")
      or die("Could not connect : " . mysql_error());
    mysql_select_db("dms") or die("Could not select database");
    //******************提取學(xué)院信息 ******************
    $queryCol = "select * from colleges order by college_id ";
    mysql_query("SET NAMES 'gb2312'");
    $result1 = mysql_query($queryCol) or die("Query failed : " . mysql_error());
    $colleges = array();
    while( $row1 = mysql_fetch_array($result1) )
    {
      $colleges[] = $row1;
    }
    //print_r ($forum_data);
    mysql_free_result($result1);
    //**************獲取專業(yè)信息 **************  
    $queryMaj = "select * from majors order by college_id desc";
    mysql_query("SET NAMES 'gb2312'");
    if( !($result2 = mysql_query($queryMaj)) )
    {
      die('Could not query t_city list');
    }
    $majors = array();
    while( $row2 = mysql_fetch_array($result2) )
    {
      $majors[] = $row2;
    }
    mysql_free_result($result2);
    &#63;>
    <!--************ JavaScript處理 college-onChange *************-->
    <script language = "JavaScript">
     var majorCount; // 存儲專業(yè)記錄條數(shù)
     // form_majors[] 儲存專業(yè) major數(shù)據(jù),如 {(1,1,電子商務(wù) ),(4,1,計算機科學(xué) ),(3,2,古典文學(xué) )}
     form_majors = new Array();
     <&#63;php
       $num2 = count($majors); // $num2 獲取專業(yè)表中記錄的個數(shù)
     &#63;>
       majorCount = <&#63;php echo $num2;&#63;>;
     <&#63;
       for($j=0;$j<$num2;$j++) // 從 0開始取出上面 majors[]中存儲的專業(yè)數(shù)據(jù)填充數(shù)組
     {
     &#63;>
       form_majors[<&#63;echo $j;&#63;>] = new Array("<&#63;echo $majors[$j]['major_id'];&#63;>","<&#63;echo $majors[$j]['college_id'];&#63;>","<&#63;echo $majors[$j]['name'];&#63;>");
     <&#63;php
     }
     &#63;>
     function changeCollege(college_id)
     {
       document.stu_add_form.major.length = 0;
       var id=id;
       var j;
       document.stu_add_form.major.options[0] = new Option('==選擇專業(yè) ==',''); // label的 value為空 ' '
       for (j=0;j < majorCount; j++) // 從 0開始判斷
       {
        if (form_majors[j][1] == college_id) // if college_id等于選擇的學(xué)院的 id
        {
           document.stu_add_form.major.options[document.stu_add_form.major.length] = new Option(form_majors[j][2], form_majors[j][0]);
        }
       }
     }
    </script>
    <!--********************頁面表單 *************************-->
    <form name="stu_add_form" method="post">
    選擇: <select name="college" onChange="changeCollege(document.stu_add_form.college.options[document.stu_add_form.college.selectedIndex].value)" size="1">
    <option selected>==請選擇學(xué)院 ==</option>
    <&#63;php
    $num = count($colleges);
    for($i=0;$i<$num;$i++)
    {
    &#63;>
    <option value="<&#63;echo $colleges[$i]['college_id'];&#63;>"><&#63;echo $colleges[$i]['name'];&#63;></option>
    <&#63;
    }
    &#63;>
    </select>
    <select name="major">
    <option selected value="">==選擇專業(yè) ==</option>
    </select>
    </form>
    </body>
    </html>
    
    

    sql statement:

    --
    -- 表的結(jié)構(gòu) `colleges`
    --
    CREATE TABLE IF NOT EXISTS `colleges` (
     `college_id` int(8) NOT NULL auto_increment COMMENT '學(xué)院編號自動增加',
     `name` varchar(40) NOT NULL COMMENT '學(xué)院名稱',
     PRIMARY KEY (`college_id`),
     UNIQUE KEY `name` (`name`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=7 ;
    --
    -- 導(dǎo)出表中的數(shù)據(jù) `colleges`
    --
    INSERT INTO `colleges` (`college_id`, `name`) VALUES
    (4, '化學(xué)與化工學(xué)院'),
    (1, '計算機與信息科學(xué)學(xué)院'),
    (6, '美術(shù)學(xué)院'),
    (2, '文學(xué)院'),
    (5, '音樂學(xué)院'),
    (3, '政治與公共管理學(xué)院');
    --
    -- 表的結(jié)構(gòu) `majors`
    --
    CREATE TABLE IF NOT EXISTS `majors` (
     `major_id` int(8) NOT NULL auto_increment COMMENT '專業(yè)號,自動增加',
     `name` varchar(40) NOT NULL COMMENT '專業(yè)名',
     `college_id` int(8) default NULL COMMENT '所在學(xué)院',
     `counsellor_id` int(10) default NULL COMMENT '輔導(dǎo)員',
     PRIMARY KEY (`major_id`),
     UNIQUE KEY `college_id` (`college_id`,`counsellor_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=gb2312 AUTO_INCREMENT=8 ;
    --
    -- 導(dǎo)出表中的數(shù)據(jù) `majors`
    --
    INSERT INTO `majors` (`major_id`, `name`, `college_id`, `counsellor_id`) VALUES
    (1, '電子商務(wù)', 1, 1),
    (2, '音樂視唱', 5, 1),
    (3, '古典文學(xué)', 2, 1),
    (4, '計算機科學(xué)', 1, NULL),
    (5, '自動化', 1, NULL),
    (6, '現(xiàn)代文學(xué)', 2, NULL),
    (7, '新聞寫作', 2, NULL);
    
    

    Readers who are interested in more PHP-related content can check out the special topics of this site: "Summary of PHP database operation skills based on pdo", "PHP MongoDB database operation skills collection", "php object-oriented programming introductory tutorial", "php Summary of String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of PHP Common Database Operation Skills"

    I hope this article will be helpful to everyone in PHP programming.

    www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1125889.htmlTechArticleDetailed explanation of the effect of the secondary linkage menu implemented by php mysql. The example of mysql linkage in this article describes the secondary linkage implemented by php mysql. Menu effects. Share it with everyone for your reference, the details are as follows: !-...
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    Using std::chrono in C Using std::chrono in C Jul 15, 2025 am 01:30 AM

    std::chrono is used in C to process time, including obtaining the current time, measuring execution time, operation time point and duration, and formatting analysis time. 1. Use std::chrono::system_clock::now() to obtain the current time, which can be converted into a readable string, but the system clock may not be monotonous; 2. Use std::chrono::steady_clock to measure the execution time to ensure monotony, and convert it into milliseconds, seconds and other units through duration_cast; 3. Time point (time_point) and duration (duration) can be interoperable, but attention should be paid to unit compatibility and clock epoch (epoch)

    How does PHP handle Environment Variables? How does PHP handle Environment Variables? Jul 14, 2025 am 03:01 AM

    ToaccessenvironmentvariablesinPHP,usegetenv()orthe$_ENVsuperglobal.1.getenv('VAR_NAME')retrievesaspecificvariable.2.$_ENV['VAR_NAME']accessesvariablesifvariables_orderinphp.iniincludes"E".SetvariablesviaCLIwithVAR=valuephpscript.php,inApach

    mysql common table expression (cte) example mysql common table expression (cte) example Jul 14, 2025 am 02:28 AM

    CTE is a temporary result set in MySQL used to simplify complex queries. It can be referenced multiple times in the current query, improving code readability and maintenance. For example, when looking for the latest orders for each user in the orders table, you can first obtain the latest order date for each user through the CTE, and then associate it with the original table to obtain the complete record. Compared with subqueries, the CTE structure is clearer and the logic is easier to debug. Usage tips include explicit alias, concatenating multiple CTEs, and processing tree data with recursive CTEs. Mastering CTE can make SQL more elegant and efficient.

    Why We Comment: A PHP Guide Why We Comment: A PHP Guide Jul 15, 2025 am 02:48 AM

    PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu

    how to avoid undefined index error in PHP how to avoid undefined index error in PHP Jul 14, 2025 am 02:51 AM

    There are three key ways to avoid the "undefinedindex" error: First, use isset() to check whether the array key exists and ensure that the value is not null, which is suitable for most common scenarios; second, use array_key_exists() to only determine whether the key exists, which is suitable for situations where the key does not exist and the value is null; finally, use the empty merge operator?? (PHP7) to concisely set the default value, which is recommended for modern PHP projects, and pay attention to the spelling of form field names, use extract() carefully, and check the array is not empty before traversing to further avoid risks.

    PHP prepared statement with IN clause PHP prepared statement with IN clause Jul 14, 2025 am 02:56 AM

    When using PHP preprocessing statements to execute queries with IN clauses, 1. Dynamically generate placeholders according to the length of the array; 2. When using PDO, you can directly pass in the array, and use array_values to ensure continuous indexes; 3. When using mysqli, you need to construct type strings and bind parameters, pay attention to the way of expanding the array and version compatibility; 4. Avoid splicing SQL, processing empty arrays, and ensuring data types match. The specific method is: first use implode and array_fill to generate placeholders, and then bind parameters according to the extended characteristics to safely execute IN queries.

    Choosing appropriate data types for columns in MySQL tables Choosing appropriate data types for columns in MySQL tables Jul 15, 2025 am 02:25 AM

    WhensettingupMySQLtables,choosingtherightdatatypesiscrucialforefficiencyandscalability.1)Understandthedataeachcolumnwillstore—numbers,text,dates,orflags—andchooseaccordingly.2)UseCHARforfixed-lengthdatalikecountrycodesandVARCHARforvariable-lengthdata

    PHP header redirect not working PHP header redirect not working Jul 14, 2025 am 01:59 AM

    Reasons and solutions for the header function jump failure: 1. There is output before the header, and all pre-outputs need to be checked and removed or ob_start() buffer is used; 2. The failure to add exit causes subsequent code interference, and exit or die should be added immediately after the jump; 3. The path error should be used to ensure correctness by using absolute paths or dynamic splicing; 4. Server configuration or cache interference can be tried to clear the cache or replace the environment test.

    See all articles