Question

I am trying to take a drop down box in PHP and select one item from the first box. 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. The main thing I am trying to get past is when I click on one of my options in the drop down box, I need to be able to submit it, or better yet, have it dynamically update to a variable. here is a piece of the code I am working with.

$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/>";

No correct solution

OTHER TIPS

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


});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top