Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Arvin Ababao
lab-exercises
Commits
b1b819e7
Commit
b1b819e7
authored
Oct 29, 2015
by
Sorrel Harriet
Browse files
adding the up to date order and orders views
parent
96c4df40
Changes
2
Hide whitespace changes
Inline
Side-by-side
week-6/record-store-app/views/order.php
0 → 100644
View file @
b1b819e7
<?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>£"
.
$row
[
'price'
]
.
"</td>"
;
$content
.
=
"<td>£"
.
$subtotal
.
"</td>"
;
$content
.
=
"</tr>"
;
}
$content
.
=
"<tr><td colspan=4><b>TOTAL</b><td><b>£"
.
$total
.
"</b></td></tr>"
;
$content
.
=
"</tbody></table>"
;
// free result set
mysqli_free_result
(
$result
);
}
}
// output the content HTML
echo
$content
;
?>
week-6/record-store-app/views/orders.php
0 → 100644
View file @
b1b819e7
<?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
;
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment