Advertisement
Guest User

Untitled

a guest
May 12th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?php
  2.  
  3. $user = 'root'; //Enter your mySQL server username
  4. $pass = ''; //enter your mySQL server password
  5. $dbh = new PDO('mysql:host=localhost;dbname=web', $user, $pass);
  6. //Gets the searched actor's id, tiebreaker is filmCount
  7. $q1 = "SELECT id
  8. FROM actors
  9. WHERE (first_name LIKE '".$_GET['firstname']." %' OR first_name = '".$_GET['firstname']."') AND last_name = '".$_GET['lastname']."'
  10. AND film_count >= all(SELECT *
  11. FROM actors
  12. WHERE (first_name LIKE'".$_GET['firstname']." %' OR first_name = '".$_GET['firstname']."')
  13. AND last_name = '".$_GET['lastname']."')";
  14. $id = null;
  15. //only returns 1 row
  16.  
  17. if(!empty($dbh->query($q1))){
  18. foreach($q1 as $row){
  19. $id = $row['id'];
  20. }
  21. }
  22. //If actor is not in the database
  23. else if($id == null){
  24. echo "Actor ";
  25. echo $_GET['firstname'];
  26. echo " ";
  27. echo $_GET['lastname'];
  28. echo " not found.";
  29. }
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement