mysql - PHP - How to show restaurant bookings -
i have database of reservations restaunt. contains menu of want. sql query shows , want show on website
this shows 2 orders, , menu items of each order. want show these 2 separate orders on website. php code follows using pdo, excluding database connection , query etc.
$resultset = $conn->query($query, pdo::fetch_obj); while($result=$resultset->fetch()) { echo "order details:<br> customerid: $result->customerid<br>paymentid: $result->paymentid<p> booking details:<br> date: $result->date<br> time: $result->time <p>menu items:<br>"; echo "$result->mealname x$result->quantity<br>"; } ?>
however, outputs website so;
order details: customerid: 1 paymentid: 1 booking details: date: 2016-01-22 time: 21:00:00 menu items: mexican rib eye steak x2 order details: customerid: 1 paymentid: 1 booking details: date: 2016-01-22 time: 21:00:00 menu items: mexican mess x2 order details: customerid: 1 paymentid: 1 booking details: date: 2016-01-22 time: 21:00:00
i want customerid/paymentid displayed once per order, items underneath.
how go doing this?
you want group reservation id, since customer can place more 1 order on same day. said, i'd order query customer id reservation id. adjust loop detects when reservation id changes on last iteration. when does, output customer information. this:
$last = null; while (...) { if ($result->reservationid !== $last) { // output per-order header } // output item details $last = $result->reservationid; }
alternatively, in 2 steps -- first list of orders today, each, display detail. more object-oriented approach. you'd have write class each object. example:
$restaurant = new restaurant($id); foreach ($restaurant->getordersfordate($today) $order) { $order->render(); }
where order::render() method like:
public function render() { $this->renderheader(); foreach ($this->getitems() $item) { $item->render(); } $this->renderfooter(); }
Comments
Post a Comment