如何在同一张表中显示订单中的所有信息? 所以我在我的数据库中有这样的
id id_transaction id_product product type nr_buc user phone adress status date_order
1 1 1 Lamb Doner Kebab small 1 Adrian Nicolae Cozma phone adress 0 2015-03-09 10:19:09
2 1 13 Cheeseburger large 3 Adrian Nicolae Cozma phone adress 0 2015-03-09 10:19:09
3 1 33 330ml Cans standard 4 Adrian Nicolae Cozma phone adress 0 2015-03-09 10:19:09
4 2 66 Portion of Fresh Nan Bread standard 1 Nicolae C. phone Home 0 2015-03-09 10:19:09
5 2 39 Red bull standard 1 Nicolae C. phone Home 0 2015-03-09 10:19:09
我希望使用下面的产品显示每个id_transaction的表格,当没有产品时,搜索下一个id_transactions并获取产品并将它们放在另一个表格中。
在这一刻,我的代码创建了具有相同信息的表*(产品数量),我不知道错误是什么。请帮帮我。
<h1>Orders</h1>
<?php
$sqlTranzactii = "SELECT id_transaction, DATE_FORMAT(date_order, '%d-%m-%Y') as data_tranzactie, user, nr_buc, phone, adress FROM orders WHERE status = 0";
$resursaTranzactii = mysql_query($sqlTranzactii);
while ($rowTranzactie = mysql_fetch_array($resursaTranzactii)) {
?>
<form action="prelucrare_comenzi.php" method="post">
Order Date:
<b><?= $rowTranzactie['data_tranzactie'] ?></b>
<div class="tranzactie">
Buyer:
<b><?= $rowTranzactie['user'] ?></b><br />
Adress:
<?= $rowTranzactie['adress'] ?><br />
Phone contact:
<?= $rowTranzactie['phone'] ?>
<table class="table table-hover table-condensed">
<thead>
<tr>
<th>no. of items</th>
<th>Product</th>
<th>Size</th>
<th>Total</th>
</tr>
</thead>
<?php
$sqlCarti = "SELECT nr_buc, product, type FROM orders WHERE status = 0 and id_transaction=" . $rowTranzactie['id_transaction'] . "";
$resursaCarti = mysql_query($sqlCarti);
while ($rowCarte = mysql_fetch_array($resursaCarti)) {
echo '<tr><th>'
. $rowCarte['nr_buc'] . '</th>
<th>
' . $rowCarte['product'] . '</th>
<th>'
. $rowCarte['type'] . '</th>';
$total = $rowCarte['price'] * $rowCarte['nr_buc'];
echo'<th>£' . $total . '</th>';
$totalGeneral = $totalDeneral + $total;
}
?>
<tr>
<th colspan="3" align="right"> Total order price: </th>
<th><?= $totalGeneral ?> £ </th>
</tr>
</table>
<input type="hidden" name="id_tranzactie" value="<?= $rowTranzactie['id'] ?>" />
<input type="submit" name="comanda_onorata" value="Comanda Onorata" />
<input type="submit" name="anuleaza_comanda" value="Anuleaza comanda" />
</div>
</form><br>
<?php
}
?>