首页 > 解决方案 > 从数组生成值到下拉列表

问题描述

在此处输入图像描述

所以我想根据学生的大学只显示特定的课程,这些课程将来自某个数组,而不是仅仅列出所有课程......我想我有点明白逻辑,但课程没有显示。

这是我的代码:

<div class="student_reg">
    <form action = "registration.php" method="post">
        <input type="text" name="sn" placeholder="Student Number"><br>
        <input type="text" name="fname" placeholder="Firstname"><br>
        <input type="text" name="lname" placeholder="Lastname"><br>
        <input type="text" name="age" placeholder="Age"><br>
        <input type="password" name="pass" placeholder="Password"><br>
        <input type="password" name="pass2" placeholder="Confirm Password"><br><br>
        <textarea rows = "5" cols = "30" placeholder="Address" name = "address"></textarea><br><br>
        <label>Year Level</label>
        <select name = "yearLevel">
            <option>1st</option>
            <option>2nd</option>
            <option>3rd</option>
            <option>4th</option>
            <option>5th</option>
        </select><br><br>
        <select name = "college">
            <option value = "">College</option>
            <option>College of Engineering</option>
            <option>College of Fine Arts, Architecture and Design</option>
        </select><br><br>
        <?php
            $cengr = array("BSME", "BSECE", "BSCpE", "BSIE", "BSCE");
            $cfad = array("BSA", "BSID", "BFA Painting", "BFA Visual Com", " Multimedia Arts");
        ?>
        <select name = 'course'>
            <option value = "">Course</option>
        <?php
            if(isset($_POST['college'])){
                if($_POST['college'] == "College of Engineering"){
                    foreach($cengr as $course => $value){
                            echo "<option value =".$course.">".$value."</option>";
                    }
                }
                if($_POST['college'] == "College of Fine Arts, Architecture and Design"){
                    foreach($cfad as $course => $value){
                            echo "<option value =".$course.">".$value."</option>";
                    }
                }   
            }
        ?>
        </select>
    </form>
</div>

标签: phphtml

解决方案


推荐阅读