从mysql动态更新php下拉

时间:2011-08-26 17:09:11

标签: php mysql drop-down-menu dynamic

我有一个从mysql填充的下拉列表

<?php
    include 'connectionvtc.php' ;


    $sql2=("SELECT DISTINCT
                subscription.subject_id,
                subject.subjectname as 'subjectname'
            FROM 
                subscription
            INNER JOIN 
                subject 
            ON 
                subject.subject_id=subscription.subject_id
            WHERE 
                (subscription.student_id = '" .mysql_real_escape_string($_SESSION['student_id']) . "')");               


    $result2=mysql_query($sql2); 
    echo '<select name="sublist">';
    echo '<option value=""></option>';

    while ($row2 = mysql_fetch_assoc($result2))
    {
        echo '<option value="' . $row2['subject_id'] . '">' . $row2['subjectname']. '</option>';
    }
    echo '</select>';                                           
?>

当在上面的下拉列表中选择了一个值时,我想填充另一个下拉列表,其代码如下:

<?php 
    include 'connectionvtc.php' ;
    $sql2=("SELECT DISTINCT 
                subscription.subject_id,     
                subject.faculty_id
            FROM 
                subscription
            INNER JOIN 
                subject 
            ON 
                facultyregister.faculty_id=subscription.faculty_id
            WHERE 
                (subscription.student_id = '" . mysql_real_escape_string($_SESSION['student_id']) . "')
                AND (subscription.subject_id = '" . mysql_real_escape_string($_SESSION[**WHATEVER VALUE I GET FROM PREVIOUS DROP DOWN**]) . "')");

    $result2=mysql_query($sql2); 

    echo '<select name="faclist">';
    echo '<option value=""></option>';

    while ($row2 = mysql_fetch_assoc($result2))
    {
        echo '<option value="' . $row2['faculty_id'] . '">' . $row2['faculty_id']. '</option>';
    }
    echo '</select>';                                               
?> 

虽然我在第二个下拉列表中的sql基于之前的下拉列表从mysql获取,但我似乎无法填充第二个下拉列表

AND (subscription.subject_id = '" . mysql_real_escape_string($_SESSION[**WHATEVER VALUE I GET FROM PREVIOUS DROP DOWN**]) . "')");

感谢您的帮助

0 个答案:

没有答案