是否可以在更改下拉列表的值时运行viewtb.php?
这就是我所拥有的,但我仍然需要使用提交按钮来查看该表。
<form method="POST">
<select id="selectcourse" name="selectcourse">
<?php
$sql = mysql_query("SELECT crs_name FROM sp_crs");
while ($crs_name = mysql_fetch_array($sql)){
echo "<option>" . $crs_name['crs_name'] . "</option>";
}
?>
</select>
<input type="submit" name="Submit" value="View Subjects">
</form>
<?php
$host="localhost";
$username="root";
$password="";
$db_name = "db_sp_dwcsj";
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
viewtb.php
<?php
if(isset($_POST['Submit'])){
$sort = $_POST['selectcourse'];
$order = "SELECT sbj_name FROM sp_crs_ml where crs_name='$sort'";
$result = mysql_query($order);
while($data = mysql_fetch_row($result)){
echo("
<table border=1
<tr>
<td>
$data[0]
</td>
</tr>
</table>");
}
}
?>