ハイ、
トレーニング目的で PHP ショップを作成しています。ユーザーが最後に行った注文を表示できるようにしたいのですが、これを実現するのに問題があります。
データベースにこれらのテーブルがあります:
顧客(子供、名前、住所、...)
製品(pid、product_name、product_description、価格)
注文--> oid、子供、支払い、住所、ステータス
order_detail --> oid、日付、pid、数量)
わかりました、クエリがデータベースから必要なデータを取得する関数を作成しました
function showOrder($kid)
{
$db = database();
$orders = $db->query ("SELECT * FROM orders
INNER JOIN order_detail on orders.oid=order_detail.oid
INNER JOIN products on order_detail.pid = products.pid
WHERE kid='$kid' ");
$orders = $orders->fetchAll();
$lastoid = 0;
foreach($orders as $i){
while($lastoid != $i['oid']) {
$lastoid = $i['oid'];
echo "Ordernr: ".$lastoid."<br/>";
echo "Produktname: ".$i['product_name']."<br>";
echo "Menge: ".$i['quantity']."<br/>";
echo "Preis: ".$i['price']."<br/>";
echo "Status: ".$i['status']."<br/>";
echo "<br/><br/><hr/>";
}
}
}
私がやりたいこと: 単一の注文をテーブルにリストします (--> oderid | 製品名 | 数量 | 価格 | ステータス) 注文に 1 つの製品しか含まれていない場合は機能しますが、注文が大きくなると (2 つの製品)、最初のものだけが表示されます。
$database は次のようになります。
Array
(
[0] => Array
(
[oid] => 1
[0] => 1
[kid] => 1
[1] => 1
[2] => 1
[date] => 2012-04-17
[3] => 2012-04-17
[pid] => 1
[4] => 1
[quantity] => 2
[5] => 2
[payment] => Nachnahme
[6] => Nachnahme
[street] => teststraße
[7] => teststraße
[number] => 2
[8] => 2
[zip] => 2222
[9] => 2222
[city] => Teststadt
[10] => Teststadt
[status] => in Bearbeitung
[11] => in Bearbeitung
[12] => 1
[product_name] => Acer Laptop
[13] => Acer Laptop
[price] => 29.00
[14] => 29.00
[details] => blabla
[15] => blabla
[category] => Laptop
[16] => Laptop
[date_added] => 2012-04-05
[17] => 2012-04-05
)
[1] => Array
(
[oid] => 1
[0] => 1
[kid] => 1
[1] => 1
[2] => 1
[date] => 2012-04-17
[3] => 2012-04-17
[pid] => 2
[4] => 2
[quantity] => 2
[5] => 2
[payment] => Nachnahme
[6] => Nachnahme
[street] => teststraße
[7] => teststraße
[number] => 2
[8] => 2
[zip] => 2222
[9] => 2222
[city] => Teststadt
[10] => Teststadt
[status] => in Bearbeitung
[11] => in Bearbeitung
[12] => 2
[product_name] => Grundig TV
[13] => Grundig TV
[price] => 22.00
[14] => 22.00
[details] => blabla
[15] => blabla
[category] => TV
[16] => TV
[date_added] => 2012-04-05
[17] => 2012-04-05
)
[2] => Array
(
[oid] => 1
[0] => 1
[kid] => 1
[1] => 1
[2] => 1
[date] => 2012-04-17
[3] => 2012-04-17
[pid] => 7
[4] => 7
[quantity] => 1
[5] => 1
[payment] => Nachnahme
[6] => Nachnahme
[street] => teststraße
[7] => teststraße
[number] => 2
[8] => 2
[zip] => 2222
[9] => 2222
[city] => Teststadt
[10] => Teststadt
[status] => in Bearbeitung
[11] => in Bearbeitung
[12] => 7
[product_name] => Nokia Handy
[13] => Nokia Handy
[price] => 69.00
[14] => 69.00
[details] => blabla
[15] => blabla
[category] => Handy
[16] => Handy
[date_added] => 2012-04-06
[17] => 2012-04-06
)
[3] => Array
(
[oid] => 2
[0] => 2
[kid] => 1
[1] => 1
[2] => 2
[date] => 2012-04-17
[3] => 2012-04-17
[pid] => 8
[4] => 8
[quantity] => 1
[5] => 1
[payment] => Vorauskasse
[6] => Vorauskasse
[street] => musterstraße
[7] => musterstraße
[number] => 1
[8] => 1
[zip] => 1111
[9] => 1111
[city] => stadt
[10] => stadt
[status] => in Bearbeitung
[11] => in Bearbeitung
[12] => 8
[product_name] => PC groß
[13] => PC groß
[price] => 66.00
[14] => 66.00
[details] => blabla
[15] => blabla
[category] => Computer
[16] => Computer
[date_added] => 2012-04-06
[17] => 2012-04-06
)
)