Commit 96c4df40 authored by Sorrel Harriet's avatar Sorrel Harriet

removing some unrequired files

parent b4e1f461
<?php
// create variable for content HTML
$content = "<h1>Artists</h1>";
// fetch records as a result set
$sql = "SELECT first_name, last_name FROM artist";
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false) {
echo mysqli_error($link);
} else {
$content .= "<table border='1'><tbody>";
// fetch associative array
while ($row = mysqli_fetch_assoc($result)) {
$content .= "<tr>";
$content .= "<td>".$row['first_name']."</td>";
$content .= "<td>".$row['last_name']."</td>";
$content .= "</tr>";
}
$content .= "</tbody></table>";
// free result set
mysqli_free_result($result);
}
// output the content HTML
echo $content;
?>
<?php
/* **************************************************************
* TASK 2: Create a view which: *
* - outputs the order details for an order based *
* on the value of the order_id parameter *
* - for each item in the order, the following *
* details should be displayed: *
* | EAN | TITLE | QUANTITY | PRICE | SUBTOTAL | *
* - the order total should also be displayed. *
****************************************************************/
// 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 = "INSERT YOUR SQL QUERY HERE!";
$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 = 0.00; // <-- CALCULATE SUBTOTAL!
$total = 0.00; // <-- KEEP RUNNING ORDER TOTAL!
$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
/* **************************************************************
* TASK 1: Create a view which: *
* - outputs a list of all transactions (orders) *
* - the orders should be grouped by customer ID *
* - each transaction links to an `order' view, setting a *
* parameter `order_id' in the URL query string *
****************************************************************/
// initialise string variable for content HTML
$content = "<h1>Orders</h1>";
// fetch all transactions (orders) and group by customer id
$sql = "INSERT YOUR SQL STATEMENT HERE!";
$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 .= "</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