我想创建一个表,我可以在一个变量(将发送给js稍后),然后显示它。但我的回声结果只是表头('Produkty','Ilość','Cena')。你能告诉我我犯了什么错误或纠正了我吗?需要有人来纠正我的mysql查询表创建
<?php
header('Access-Control-Allow-Origin: *');
include "database.php";
$dane = array();
$tabela='<table class="table table-striped">
<thead>
<tr>
<th>Produkt</th>
<th>Ilość</th>
<th>Cena</th>
</tr>
</thead>
<tbody>';
$dane=array();
$sql_main="SELECT Products.`Name`,Orders_NEW.`Amount`,((Products.`Price`)*(Orders_NEW.`Amount`)) as 'PRICE' FROM `Orders_NEW` inner join `Products` on Orders_NEW.`Product`=Products.`ID` AND `Order_ID`=669";
$dane = $db->query($sql_main);
foreach($dane as $row)
{
$tabela.="<tr><td>".$row['Name']."</td><td>".$row['Amount']."</td><td>".$row['Price']."</td></tr>";
}
$sql_second="SELECT SUM((Products.`Price`)*(Orders_NEW.`Amount`)) as 'SUMA' FROM `Orders_NEW` inner join `Products` on Orders_NEW.`Product`=Products.`ID` AND `Order_ID`=669";
$dane_second= array();
$dane_second= $db -> query($sql_second);
foreach($dane_second as $row)
{
$tabela.='<thead>
<tr>
<th>Łącznie</th>
<th></th>
<th>'.$row["SUMA"].'</th>
</tr>
</thead>
</table>';
}
echo($tabela);
?>
编辑:的foreach改为而($行= $ dane-> FETCH_ASSOC()) 现在我的结果是:
PRODUKTIlość以上的价格
Łącznie
好像变量像$ row ['Name']等是这里的问题
http://php.net/manual/en/function.error-reporting.php --- http://php.net/manual/en/mysqli.error.php - 调试是50%的乐趣。 –
请确保存在一个订单与编号669,你有这个'Order_ID = 669'在你的SQL代码 – BrunoM24
是啊我有Order_ID与编号为669,试图SQL我的SQL服务器上查询 – TheWebWeeb