索引.html:
<?php
include_once 'func.inc.php';
connect();
?>
<!doctype html>
<html>
<head>
<title>Team DriveSmart</title>
</head>
<body bgcolor="#008933" text="#ffffff">
<header>
<h1 align="center"> Team DriveSmart </h1>
</header>
<header>
<h3 align="center"> Highway State </h3>
</header>
<section>
<article>
<hgroup>
</hgroup>
<p align="center">
<form style="text-align:center" method="post" action="">
<select name="dropdown1">
<?php query1() ?>
</select>
<input type="submit" value="Submit" />
</form>
</p>
</article>
<article>
</article>
</section>
<footer>
<f1 align="center"></f1>
</footer>
<header>
<h3 align="center"> Highway ID </h3>
</header>
<section>
<article>
<hgroup>
</hgroup>
<p align="center">
<form style="text-align:center" method="post" action="">
<select name="dropdown2">
<?php query2() ?>
</select>
<input type="submit" value="Submit" />
</form>
</p>
</article>
<article>
</article>
</section>
<footer>
<f1 align="center"></f1>
</footer>
</body>
</html>
然后我的 func.inc.php 看起来像这样:
<?php
include_once 'db.inc.php';
function connect()
{
mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Error connecting" . mysql_error()) ;
mysql_select_db(DB_NAME);
}
function close()
{
mysql_close();
}
function query1()
{
$myData=mysql_query("SELECT * FROM highways_highway");
while($record = mysql_fetch_array($myData))
{
echo '<option value="' . $record['highway_state'] . '">' . $record['highway_state'] . '</option>' ;
}
}
function query2()
{
$myData=mysql_query("SELECT * FROM highways_exit");
while($record = mysql_fetch_array($myData))
{
echo '<option value="' . $record['highway_id'] . '">' . $record['highway_id'] . '</option>' ;
}
}
?>
我想做的是我想用数据库中的选项填充这些下拉菜单(例如,在 query1 中,我想用状态填充菜单)。该代码目前似乎显示了一个下拉菜单和一个提交按钮,但下拉菜单是空的,我不知道为什么。
B 部分:一旦用户从下拉菜单中选择,我想根据查询 SELECT * FROM Highways_highway WHEREhighway_state = dropdown1 显示整个 sql 表,一旦 A 部分修复,有什么建议吗?