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
e66055a4
Commit
e66055a4
authored
Oct 30, 2015
by
Sorrel Harriet
Browse files
Duplicate
parent
a2fd5b3b
Changes
1
Hide whitespace changes
Inline
Side-by-side
week-6/record-store-app/views/orders_example.php
deleted
100644 → 0
View file @
a2fd5b3b
<?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