0

我正在尝试在 PHP 中使用一个下拉框,然后从第一个框中选择一个项目。然后我想要从我的第一个下拉框中选择的项目,并将其放入我的 $lineIDSelection 变量中,以便我可以将它插入到下一个下拉框的查询中。我要克服的主要问题是,当我单击下拉框中的一个选项时,我需要能够提交它,或者更好的是,让它动态更新为变量。这是我正在使用的一段代码。

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die("could not connect to the databse!");

$select_db = mysql_select_db('camdb') or die ('could not select camdb database!!');

    $lineID = "SELECT * FROM camTable;";
    $IDresult = mysql_query($lineID);

            echo"line" . "<br/>";
            echo "<select name=\"line\">";
            while ($row = mysql_fetch_array($IDresult)) {
                echo "<option value='" . $row['line'] . "'>" . $row['line'] . "</option>";
            }
            echo "</select>" . "<br/>" . "<br/>";



    $query = "SELECT DISTINCT Length FROM camTable;";
    $result = mysql_query($query);      

            echo"Cam Length" . "<br/>";
            echo "<select name=\"Length\">";
            while ($row = mysql_fetch_array($result)) {
                echo "<option value='" . $row['Length'] . "'>" . $row['Length'] . "</option>";
            }
            echo "</select>" . "<br/>" ."<br/>";
4

1 回答 1

0
Q.I then want the selected item from my first drop down box, and placed it into 
my $lineIDSelection variable so that I can insert it into a query for the next 
drop down box

See you can achieve this by Ajax:-

On-change on first drop-down you get value and on the basis of first drop-down value you can generate second drop-down.

PHP:- assign id to drop-down

 echo "<select name='line' id='dropDown1'>";

Jquery :-

$('#dropDown1').change(function() {    
    var sel_item=$(this).val();
     // sel_item is first dropdown selected value.
     // pass it to ajax request 
         // in you ajax request get sel_item and assign it to $lineIDSelection


});
于 2013-06-07T05:40:11.803 回答