Advertisement
Guest User

Untitled

a guest
Aug 15th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.56 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.         $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  35.  
  36.         foreach($results as $row) {
  37.  
  38.             $output = '<div id="title">' .ucfirst($row['title']) . '</div>';
  39.             $output .= '<div id="poster">' .$row['poster']. '</div>';
  40.             $output .= '<div id="description">'.ucfirst($row['description']). '</div>';
  41.             $output .= '<div id="info">';
  42.             $output .= $row['imdb'] .'<br/>';
  43.             $output .= ucfirst($row['genre']) .'<br/>';
  44.             $output .= ucfirst($row['actors']) .'<br/>';
  45.             $output .= $row['playtime'] . '<br/></div>';
  46.            
  47.             $output .= '<div id="trailer">' .$row['trailer'].'</div>';
  48.         }      
  49.     }
  50. } else {
  51.   echo 'Syötä hakusana';
  52. }
  53. ?>
  54.  
  55. <!--End of normal section-->
  56.  
  57. <div id="movie_background">
  58.     <?php if(!empty($output)) {
  59.       echo $output;
  60.       }
  61.     ?>
  62. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement