链接两个动态下拉菜单php mysql

时间:2013-09-06 19:03:13

标签: php mysql drop-down-menu

我有两个从同一个表中填充的下拉菜单。我想做的是让它们自动匹配选定的值。换句话说,如果选择客户端2a,我希望在另一个下拉菜单中自动选择帐户2a,反之亦然。看起来没有jquery应该很容易,因为它们有匹配的ID,但我似乎无法实现它。

以下是代码:

<p>Client's full name: <select name="client"><option value="<? echo $c_id ?>" ><? echo $client ?></option>
<?php //retrieve all the clients and add to the pull-down menu

$q = "SELECT c_id, CONCAT_WS(' ', c_firstName, c_middleName, c_lastName)FROM client ORDER BY c_lastName, c_firstName ASC";

$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r)> 0) {
    while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
        echo "<option value=\"$row[0]\"";
        //Check for stickyness
        if (isset($_POST['client'])&&($_POST['client']== $row[0])) 
        echo ' selected="selected"';
        echo ">$row[1]</option>\n";         
    }   
}

?>

</select></p>

<p>Account nickname: <select name="nickname"><option value="<? echo $c_id ?>" ><? echo $nickname ?></option>
<?php //retrieve all the Acct Nicknames and add to the pull-down menu

$q = "SELECT c_id, c_nn FROM client ORDER BY c_nn ASC";

$r = mysqli_query ($dbc, $q);
if (mysqli_num_rows($r)> 0) {
    while ($row = mysqli_fetch_array ($r, MYSQLI_NUM)) {
        echo "<option value=\"$row[0]\"";
        //Check for stickyness
        if (isset($_POST['nickname'])&&($_POST['nickname']== $row[0])) 
        echo ' selected="selected"';
        echo ">$row[1]</option>\n";         
    }   
}
?>
</select></p>
</div>

0 个答案:

没有答案