kat_T
08-05-2010, 11:05 AM
Hi,
I have created two dynamic drop down menus from ms sql server database using PHP. The code is the following:
$sql="SELECT DISTINCT collector from dbo.missourifinal$ where long IS NOT NULL order by collector";
$sql="SELECT DISTINCT collector from dbo.table where long IS NOT NULL order by collector";
$result = sqlsrv_query( $conn, $sql);
echo "<select id='collector' name='collector'>\n"; //create the drop down menu
echo "\t<option value=\"SELECT COLLECTOR\" ";
if ($_POST['collector']=="SELECT COLLECTOR") echo "selected=\"selected\"";
echo ">---SELECT COLLECTOR---</option>\n";
while($nt=sqlsrv_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"{$nt['collector']}\"";
if ($_POST['collector']==$nt['collector']) echo "selected=\"selected\"";
echo ">$nt[collector]</option>\n";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
and the other drop down is created exactly the same way.
So the question now is:
How do I make them dependant so that when I select an option in the first drop down then the values in the second will change??
I have seen plenty examples on how to implement (with javascript and AJAX) this but none for something like the above..
Thank you in advance
Kat
I have created two dynamic drop down menus from ms sql server database using PHP. The code is the following:
$sql="SELECT DISTINCT collector from dbo.missourifinal$ where long IS NOT NULL order by collector";
$sql="SELECT DISTINCT collector from dbo.table where long IS NOT NULL order by collector";
$result = sqlsrv_query( $conn, $sql);
echo "<select id='collector' name='collector'>\n"; //create the drop down menu
echo "\t<option value=\"SELECT COLLECTOR\" ";
if ($_POST['collector']=="SELECT COLLECTOR") echo "selected=\"selected\"";
echo ">---SELECT COLLECTOR---</option>\n";
while($nt=sqlsrv_fetch_array($result)){//Array or records stored in $nt
echo "\t<option value=\"{$nt['collector']}\"";
if ($_POST['collector']==$nt['collector']) echo "selected=\"selected\"";
echo ">$nt[collector]</option>\n";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
and the other drop down is created exactly the same way.
So the question now is:
How do I make them dependant so that when I select an option in the first drop down then the values in the second will change??
I have seen plenty examples on how to implement (with javascript and AJAX) this but none for something like the above..
Thank you in advance
Kat