Commit 0ad4efad authored by Sorrel Harriet's avatar Sorrel Harriet

Merge branch 'master' of gitlab.doc.gold.ac.uk:data-networks-web/lab-exercises

parents 90f92e50 cf313a85
<?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>&pound;".$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;
?>
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