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
cf313a85
Commit
cf313a85
authored
Nov 10, 2015
by
Sorrel Harriet
Browse files
No longer needed
parent
33758618
Changes
1
Hide whitespace changes
Inline
Side-by-side
week-6/record-store-app/views/results.php
deleted
100644 → 0
View file @
33758618
<?php
$content
=
"<h1>Records Found</h1>"
;
// check if search parameter set
if
(
!
isset
(
$_GET
[
'artist_name'
]))
{
$content
.
=
"<p>Sorry, I don't know what you're looking for.</p>"
;
}
else
{
// search parameter was set
// get the name from the query string
$name
=
$_GET
[
'artist_name'
];
// split the name into an array of words
$parts
=
explode
(
" "
,
$name
);
// define query
$sql
=
"SELECT r.title, r.price, a.first_name, a.last_name
FROM record r
JOIN artist a
ON r.artist_id=a.id
WHERE a.first_name='"
.
$parts
[
0
]
.
"'
OR a.first_name='"
.
$parts
[
1
]
.
"'
OR a.last_name='"
.
$parts
[
0
]
.
"'
OR a.last_name='"
.
$parts
[
1
]
.
"'"
;
$result
=
mysqli_query
(
$link
,
$sql
);
// check query returned a result
if
(
$result
===
false
)
{
echo
mysqli_error
(
$link
);
}
else
{
// get number of rows
$num_rows
=
mysqli_num_rows
(
$result
);
// check some rows were found
if
(
$num_rows
==
0
)
{
// no rows found
$content
=
"<p>Sorry, no results found matching your query.</p>"
;
}
else
{
// some rows were found
$content
.
=
"<table border='1'><tbody>"
;
// fetch associative array
while
(
$row
=
mysqli_fetch_assoc
(
$result
))
{
// append table rows to $content string
$content
.
=
"<tr>"
;
$content
.
=
"<td>"
.
$row
[
'title'
]
.
"</td>"
;
$content
.
=
"<td>"
.
$row
[
'first_name'
]
.
"</td>"
;
$content
.
=
"<td>"
.
$row
[
'last_name'
]
.
"</td>"
;
$content
.
=
"<td>£"
.
$row
[
'price'
]
.
"</td>"
;
$content
.
=
"</tr>"
;
}
// append $content string with closing table tags
$content
.
=
"</tbody></table>"
;
// 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