我有一个简单的 php 表单,它允许用户从主题区域的下拉列表中进行选择以返回一组数据库(例如http://library.wabash.edu/biology.php)。如您所见,在做出选择并单击提交之前,不会返回任何内容。是否有可能在页面加载时已经加载了一组数据库(生物学数据库将在生物学部门页面上加载等),但还允许用户做出另一个选择,就像我现在所做的那样?我的经验不足在这里显示,所以提前道歉。
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
<select name="choice" id="choice">
<option value="Biology">Biology</option>
<option value="Chemistry">Chemistry</option>
<option value="Computer Science">Computer Science</option>
<option value="Mathematics">Mathematics</option>
<option value="Medicine">Medicine</option>
<option value="Physics">Physics</option>
</select>
<input type="submit" name="submit" value="Go" style="margin-left: 10px">
<input type="submit" name="reset" value="Clear" style="margin-left: 10px">
<input type="hidden" name="submitted" value="true"/>
</form>
<?php
if(isset($_POST['submit'])) {
$choice=$_POST['choice'];
$localhost="localhost";
$username="xxxxxxx";
$password="xxxxxxx";
$database="xxxxxxx";
$linkid=mysql_connect($localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
mysql_select_db("databases",$linkid);
$resultid=mysql_query("SELECT name, mobile, app, tutorial, help
FROM databaselist
WHERE dept
LIKE '%{$choice}%'
ORDER BY sortname ASC", $linkid);
echo"<table>";
while ($row = mysql_fetch_row($resultid))
{
echo"<tr>";
foreach ($row as $field)
{
echo"<td>$field</td>";
}
echo"</tr>";
}
echo"</table>";
mysql_close($linkid);
}
?>