【发布时间】:2014-07-04 04:53:15
【问题描述】:
我一直在创建一个连接到另一个 php 页面的下拉列表。我使用 sql 查询列出了人员名称,但我需要它们具有人员 ID 的值。我已连接页面 task7.php(其中有一个查询显示给定人员 ID 的购买信息),因此一旦用户单击名称然后单击提交,应显示该人的订单信息。目前我能够查看下拉列表,选择一个名称,但是当我单击提交时,该表只有一个空表的字段名称。这是我的代码:
<?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>
【问题讨论】:
-
我不确定这是否会对您有所帮助,但您的 HTML 无效——您的提交按钮位于结束
</select>内。修复它,看看它是否有帮助。 -
不,还有一张空桌子。我被卡住了,它甚至都不好笑:(。就像我做对了一切,但它不起作用。也许我必须使用某种表单名称或 id 或选择 id?嗯
-
我还需要从 task7.php 文件中调用任何内容吗?有一个 $staffid=$_GET["staffID"] 变量还不够吗? (除了显示购买细节的编码之外)。
-
试试
$staffid = $_GET["list"]。 -
那行不通。但我所做的是更改