我一直在创建一个连接到另一个php页面的下拉列表。我使用sql查询列出staffNames但我需要它们具有staffID的值。我已经连接了页面task7.php(它有一个显示给定staffID的购买信息的查询),所以一旦用户点击一个名字然后点击提交,就会显示人员订单信息。目前我能够查看下拉列表,选择一个名称,但是当我单击提交时,表中只有一个带有空表的字段名称。以下是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Prac 2 Task 9</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "twa291", ".......");
mysql_select_db("factory291", $conn)
or die ('Database not found ' . mysql_error() );
?>
<form method="get" action="task7.php">
<select name="list" id="list" size="12">
<?php
$sql = "SELECT staffID, staffName FROM staff";
$result = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
while ($row = mysql_fetch_array($result)){
$title=$row["staffName"];
$id=$row["staffID"];
echo "<option value= ".$id.">".$title."</option>";
}
?>
<input type="submit" value="Submit" method="get">
</select>
</form>
<?php
mysql_close($conn); ?>
</body>
</html>
这是我的task7.php文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Prac 2 Task 3</title>
</head>
<body>
<?php
$conn = mysql_connect("localhost", "twa291", "......");
mysql_select_db("factory291", $conn)
or die ('Database not found ' . mysql_error() ); ?>
<?php
$staffid= $_GET["staffID"];
?>
<?php
$sql = "SELECT orderID, orderDate, orderDate, shippingDate, staffName FROM purchase,
staff
WHERE staff.staffID='$staffid'";
$rs = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
?>
<table border="1" summary="Staff Orders">
<tr>
<th>Order ID</th>
<th>Order Date</th>
<th>Shipping Date</th>
<th>Staff Name</th>
</tr>
<?php
while ($row = mysql_fetch_array($rs)) { ?>
<tr>
<td><?php echo $row["orderID"]?></td>
<td><?php echo $row["orderDate"]?></td>
<td><?php echo $row["shippingDate"]?></td>
<td><?php echo $row["staffName"]?></td>
</tr>
<?php }
mysql_close($conn); ?>
</table>
</body>
</html>
答案 0 :(得分:0)
您已使用" "
<?php
$sql = "SELECT staffID, staffName FROM staff";
$result = mysql_query($sql, $conn)
or die ('Problem with query' . mysql_error());
while ($row = mysql_fetch_array($result))
{
$title=$row["staffName"];
$id=$row["staffID"];
echo "<option value= '.$id.'>".$title."</option>";
}
?>
答案 1 :(得分:0)
?php
$staffid= $_GET["list"];
?>
<?php
$sql = "SELECT orderID, orderDate, orderDate, shippingDate, staffName FROM purchase,
staff
WHERE staff.staffID='$staffid'";
?>