gpt4 book ai didi

php - 显示下拉列表中的结果

转载 作者:行者123 更新时间:2023-11-30 00:15:37 25 4
gpt4 key购买 nike

我一直在创建一个连接到另一个 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>

最佳答案

您用 "" 包裹了不需要的字符串

<?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>";

}

?>

关于php - 显示下拉列表中的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23683370/

25 4 0
文章推荐: mysql - Datasnap/dbExpress 部署问题
文章推荐: javascript - 不确定为什么 React 无法呈现
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com