Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $user = 'root'; //Enter your mySQL server username
- $pass = ''; //enter your mySQL server password
- $dbh = new PDO('mysql:host=localhost;dbname=web', $user, $pass);
- //Gets the searched actor's id, tiebreaker is filmCount
- $q1 = "SELECT id
- FROM actors
- WHERE (first_name LIKE '".$_GET['firstname']." %' OR first_name = '".$_GET['firstname']."') AND last_name = '".$_GET['lastname']."'
- AND film_count >= all(SELECT *
- FROM actors
- WHERE (first_name LIKE'".$_GET['firstname']." %' OR first_name = '".$_GET['firstname']."')
- AND last_name = '".$_GET['lastname']."')";
- $id = null;
- //only returns 1 row
- if(!empty($dbh->query($q1))){
- foreach($q1 as $row){
- $id = $row['id'];
- }
- }
- //If actor is not in the database
- else if($id == null){
- echo "Actor ";
- echo $_GET['firstname'];
- echo " ";
- echo $_GET['lastname'];
- echo " not found.";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement