Advertisement
Guest User

Untitled

a guest
Aug 15th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. <?php
  2. error_reporting(E_ALL);
  3.  
  4. $dsn = 'mysql:dbname=movies;host=127.0.0.1';
  5. $user = 'root';
  6. $password = '';
  7.  
  8. try {
  9. $pdo = new PDO($dsn, $user, $password);
  10.  
  11. } catch (PDOException $e) {
  12.  
  13. echo 'Connection failed: ' . $e->getMessage();
  14. }
  15.  
  16. if(isset($_POST['submit']) && strlen($_POST['search']) > 1) {
  17.  
  18. $searchq = $_POST['search'];
  19. $data = array();
  20.  
  21. $sql = "SELECT * FROM `movie-info` WHERE `keywords` LIKE :keyword";
  22. $stmt = $pdo->prepare($sql);
  23.  
  24. $stmt->execute(array(
  25. 'keyword' => '%' . $_POST['search'] . '%'
  26. ));
  27.  
  28. if($stmt->rowCount() == 0) {
  29.  
  30. echo 'Ei hakutuloksia!';
  31. exit();
  32.  
  33. } else {
  34.  
  35. $i = 0;
  36.  
  37. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  38.  
  39. foreach($results as $row) {
  40.  
  41. $output = '<div id="title">
  42. '.ucfirst($row['title']).'
  43. </div>';
  44. $output .= '<div id="poster">
  45. '.$row['poster'].'
  46. </div>';
  47. $output .= '<div id="description">
  48. '.ucfirst($row['description']).'
  49. </div>';
  50. $output .= '<div id="info">
  51. '.$row['imdb'].'<br>
  52. '.ucfirst($row['genre']).'<br>
  53. '.ucfirst($row['actors']).'<br>
  54. '.ucfirst($row['playtime']).'<br>
  55. </div>';
  56. $output .= '<div id="trailer">
  57. '.$row['trailer'].'
  58. </div>';
  59. }
  60.  
  61. }
  62. } else {
  63. echo 'Syötä hakusana';
  64. }
  65. ?>
  66.  
  67. <!--End of normal section-->
  68.  
  69. <div id="movie_background">
  70. <?phpif(!empty($output)) {echo $output;}?>
  71. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement