Commit b1b819e7 authored by Sorrel Harriet's avatar Sorrel Harriet

adding the up to date order and orders views

parent 96c4df40
<?php
// check the order_id parameter has been set in the URL
if (isset($_GET['order_id']))
{
$order_id = $_GET['order_id'];
} else {
$order_id = -1; // if not, set to an implausible value
}
// fetch order details associated with current order id
$sql = "SELECT r.ean, r.title, ol.quantity, ol.transaction_id, r.price
FROM record r
INNER JOIN orderline ol
ON ol.record_ean=r.ean
WHERE ol.transaction_id=".$order_id;
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false) {
echo mysqli_error($link);
} else {
// Find the number of rows returned
$num_rows = mysqli_num_rows($result);
// Check it's not 0
if ($num_rows == 0) {
$content = "<h1>Order not found</h1>";
} else {
// create variable for content HTML
$content = "<h1>Order ".$order_id."</h1>";
$content .= "<table border='1'>";
$content .= "<thead><tr>
<th>EAN</th>
<th>Title</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
</tr></thead>";
$content .= "<tbody>";
// initialise total order price to 0
$total = 0.00;
// fetch associative array
while ($row = mysqli_fetch_assoc($result)) {
$subtotal = $row['quantity'] * $row['price'];
$total = $total + $subtotal;
$content .= "<tr>";
$content .= "<td>".$row['ean']."</td>";
$content .= "<td>".$row['title']."</td>";
$content .= "<td>".$row['quantity']."</td>";
$content .= "<td>&pound;".$row['price']."</td>";
$content .= "<td>&pound;".$subtotal."</td>";
$content .= "</tr>";
}
$content .= "<tr><td colspan=4><b>TOTAL</b><td><b>&pound;".$total."</b></td></tr>";
$content .= "</tbody></table>";
// free result set
mysqli_free_result($result);
}
}
// output the content HTML
echo $content;
?>
<?php
// initialise string variable for content HTML
$content = "<h1>Orders</h1>";
// fetch all transactions (orders) and group by customer id
$sql = "SELECT id, customer_id FROM transaction
ORDER BY customer_id";
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false)
{
echo mysqli_error($link);
} else {
$num_rows = mysqli_num_rows($result);
if ($num_rows > 0)
{
$content .= "<table border='1'>";
$content .= "<thead><tr><th>Order ID</th><th>Customer ID</th></tr></thead>";
$content .= "<tbody>";
// fetch each row in result set as an associative array
while ($row = mysqli_fetch_assoc($result)) {
$content .= "<tr>";
$content .= "<td><a href=\"?page=order&order_id=".$row['id']."\">".$row['id']."</a></td>";
$content .= "<td>".$row['customer_id']."</td>";
$content .= "</tr>";
}
$content .= "</tbody></table>";
} else {
$content .= "<p>There are no orders to display.</p>";
}
// free result set
mysqli_free_result($result);
}
// output the content HTML
echo $content;
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment