Php 如何在表的td中填充组合框
我想从数据库中检索一些数据并将它们显示在一个表中,我需要将一个字段Php 如何在表的td中填充组合框,php,sql,html,pdo,combobox,Php,Sql,Html,Pdo,Combobox,我想从数据库中检索一些数据并将它们显示在一个表中,我需要将一个字段Order\u Status作为组合框,它的数据从另一个表中填充,并在组合的开头添加从数据库返回的行的结果 数据需要如下所示,在红色的“待编辑”组合框中。 问题在于,我无法将字段Order\u status的结果作为组合框显示在表的td中 $stmt ="SELECT distinct Order_ID,Customer_ID,Required_Date,Order_Status FROM Orders where Requi
Order\u Status
作为组合框,它的数据从另一个表中填充,并在组合的开头添加从数据库返回的行的结果
数据需要如下所示,在红色的“待编辑”组合框中。
问题在于,我无法将字段Order\u status
的结果作为组合框显示在表的td中
$stmt ="SELECT distinct Order_ID,Customer_ID,Required_Date,Order_Status FROM Orders where Required_Date between '".$SDate."' and '".$EDate."'";
$row = $conn->query($stmt)->fetchall(PDO::FETCH_ASSOC);
if (count($row) > 0)
{
$output.='<hr />
<table class="table1">
<tr>
<th>Order No.</th>
<th>Customer Name</th>
<th>Order Details</th>
<th>Delivery Date</th>
<th>Order Status</th>
</tr>
';
foreach ($conn->query($stmt) as $rows)
{
//Getting Customer Name
$sql="SELECT nick_name_ FROM Customers where Cust_id='".$rows["Customer_ID"]."'";
$result=$conn->query($sql)->fetch(PDO::FETCH_ASSOC);
//Getting Order Data
$query="SELECT * FROM Order_Product where Order_ID='".$rows["Order_ID"]."'";
foreach ($conn->query($query) as $results)
{
$newsql="SELECT Category_Name from Categories where Category_ID='".$results['Category_ID']."'";
$newresult=$conn->query($newsql)->fetch(PDO::FETCH_ASSOC);
$CatName=$newresult['Category_Name'];
$newsql="SELECT Product_Name from Products where Product_ID='".$results['Product_ID']."'";
$newresult=$conn->query($newsql)->fetch(PDO::FETCH_ASSOC);
$ProName=$newresult['Product_Name'];
$output.='
<tr>
<td>'.$rows['Order_ID'].'</td>
<td>'.$result['nick_name_'].'</td>
<td>'.$CatName.",".$ProName." ".$results['Amount'].'</td>
<td>'.$rows['Required_Date'].'</td>
';
$stmt = "SELECT * FROM Order_Status WHERE Status_Name !='".$rows['Order_Status']."'";
//$res = $conn->query($sql)->fetch(PDO::FETCH_ASSOC);
foreach ($conn->query($stmt) as $res)
{
$output.='<td>'
?>
<option value="<?php echo $res['Status_ID']; ?>"><?php echo $res['Status_Name']; ?></option>
<?php
'</td>
</tr>
';
}
}
}
$output.='</table>';
$bool_is_data_saved = true;
echo $output;
}
if(!$bool_is_data_saved)
{
echo ("Failed");
}
$stmt=“从订单中选择不同的订单ID、客户ID、所需日期、订单状态,其中所需日期介于“..SDate.”和“..EDate.”之间;
$row=$conn->query($stmt)->fetchall(PDO::FETCH_ASSOC);
如果(计数($row)>0)
{
$output.='
订单号。
客户名称
订单详情
交货日期
订单状态
';
foreach($conn->query($stmt)作为$rows)
{
//获取客户名称
$sql=“从客户id=”的客户中选择尼克•名称”。$rows[“客户id”]。”;
$result=$conn->query($sql)->fetch(PDO::fetch_ASSOC);
//获取订单数据
$query=“从订单产品中选择*,其中订单ID=”$rows[“订单ID”]。“”;
foreach($conn->query($query)作为$results)
{
$newsql=“从类别中选择类别名称,类别ID=”$results['Category\u ID']。”;
$newresult=$conn->query($newsql)->fetch(PDO::fetch_ASSOC);
$CatName=$newresult['Category_Name'];
$newsql=“从Product_ID=”的产品中选择Product_Name”。$results['Product_ID']。”;
$newresult=$conn->query($newsql)->fetch(PDO::fetch_ASSOC);
$ProName=$newresult['Product_Name'];
$output.='
“.$rows['Order_ID']”
“.$result['nick_name_']”
“.$CatName.”、“$ProName.”、“$results['Amount']”
“.$rows[“所需日期”]”
';
$stmt=“从订单状态中选择*,其中状态名称!=”$rows['Order\u Status']。”;
//$res=$conn->query($sql)->fetch(PDO::fetch_ASSOC);
foreach($conn->query($stmt)作为$res)
{
$output.=''
?>
那个密码…很难读懂
在我看来,在实际查询中执行以下操作而不是foreach更为简洁:
$stmnt = $conn->prepare("SELECT * FROM table WHERE id=?");
$stmnt->execute(array($someId));
while ($result = $stmnt->fetch()){
//do stuff
}
另外,在foreach中跳出PHP,然后在HTML中回音是很奇怪的
最后,为了使它更易于管理,我将使用从HTML调用的两个函数
为了回答您的问题,我认为问题在于您没有定义select
这样做:
$output.='<td>';
$output .= '<select name="comboBox">';
foreach ($conn->query($stmt) as $res) {
$output .= '<option value="'.$res['Status_ID'] .'">'.$res['Status_Name'],'</option>';
}
$output .= '</select>';
$output .= '</td>';
$output.='';
$output.='';
foreach($conn->query($stmt)作为$res){
$output.=''.$res['Status\u Name'],'';
}
$output.='';
$output.='';
还有一件事!
您在两个不同的位置使用$stmnt变量来执行两个不同的查询。请使用不同的变量或将查询放入函数中。这太夸张了!您遇到了什么问题?为什么要将查询语句作为行来处理>???