【发布时间】:2017-09-27 19:04:02
【问题描述】:
我想从数据库中检索一些数据并将它们显示在一个表中,我需要将一个字段Order_Status 作为一个组合框,它的数据从另一个表中填充并添加到开头组合从数据库返回的行的结果。
数据需要如下所示,红色部分为组合框。 Required Result
问题是我无法将字段 Order_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");
}
【问题讨论】:
-
这是顶天立地!你有什么问题?为什么将查询语句作为一行进行foreach>???