Skip to content

Instantly share code, notes, and snippets.

@honno
Created June 3, 2018 20:29
Show Gist options
  • Save honno/be870230d050649b8fd07d19d84c1063 to your computer and use it in GitHub Desktop.
Save honno/be870230d050649b8fd07d19d84c1063 to your computer and use it in GitHub Desktop.
<?php
$year = $_REQUEST["year"];
$rating = $_REQUEST["rating"];
$pdo = require 'connectdb.php';
$query = "
SELECT DISTINCT d.id, CONCAT(d.last_name, ', ', d.first_name) AS name
FROM directors d
JOIN movies_directors md ON md.director = d.id
JOIN movies m ON md.movie_id = m.id
WHERE m.year>=$year AND $rating<=m.rating
ORDER BY d.last_name, d.first_name
";
function tr($id, $name) {
echo = "
<tr>
<td>$id</td>
<td>$name</td>
</tr>
";
}
$results = $pdo->query($query);
if ($r->rowCount() > 0) {
echo "
<table>
<tr>
<th>Director Id</th>
<th>Name</th>
</tr>
";
foreach($results as $result) {
tr($result["id"], $result["name"]);
}
echo "</table>";
} else {
echo "<p>No directors found.</p>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment