Self submit and dynamic dropdown
Posted: Sat Dec 05, 2009 8:46 pm
I have a php page that recevies a value "$cat" from another page. It uses that value to populate a dropdown menu dynamically with selections. When the user selects one value (form the drop down) and clicks on submit, the form is supposed to self submit and run execute another query and display the results as a table.
My problem is: every time I click on submit the selection values form the first drop-down clear. But I want the selections to stay, so the user can re-use the form to submit a differnet selection.
Here is the code: The file name is "dd3ck.php"
[color=#80FFBF
My problem is: every time I click on submit the selection values form the first drop-down clear. But I want the selections to stay, so the user can re-use the form to submit a differnet selection.
Here is the code: The file name is "dd3ck.php"
Code: Select all
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Multiple drop down box</title>
</head>
<body>
<?php
if (!empty($_POST)) {
$username="root";
$password="";
$database="cs631";
// Connect to the server
$con = mysql_connect(localhost,$username,$password);
mysql_select_db($database, $con);
$cat = $_REQUEST['cat'];
$q1 = "SELECT * FROM `Station` WHERE RouteSriNumber = " . $cat;
$result = mysql_query($q1);
?>
<table>
<tr>
<td>
Select a Station ID from the List:
</td>
<form method=post name=f2 action='dd3ck.php'>
<tr><td>
<?php
echo "";
echo "<select size = 5 name='Station'>" ;
while($noticia = mysql_fetch_array($result)) {
echo "<option value='$noticia[StationID]'> $noticia[StationID] </option>";
}
echo "</select>";
}
//mysql_close($con);
?>
</td></tr>
<tr><td> <input type=submit value='Submit'></td></tr>
</form>
</table>
<?php
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$St = $_REQUEST['Station'];
If ($St <>"")
{
$username="root";
$password="";
$database="cs631";
// Connect to the server
$con = mysql_connect(localhost,$username,$password);
mysql_select_db($database, $con);
$q2 = "SELECT * FROM `Station` WHERE RouteSriNumber =" . $St;
echo $q2;
$result2 = mysql_query($q2);
echo "<table border='1'>
<tr>
<th>StationID</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['StationID'] . "</td>";
echo "<td>" . $row['Latitude'] . "</td>";
echo "<td>" . $row['Longitude'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
}
}
?>
</body>
</html>[/color]