Advertisement
Guest User

Untitled

a guest
Aug 14th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 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. // Yhteyden muodostus
  9. try {
  10. $pdo = new PDO($dsn, $user, $password); // Uusi PDO objekti
  11.  
  12. } catch (PDOException $e) {
  13.  
  14. echo 'Connection failed: ' . $e->getMessage();
  15. }
  16.  
  17. if(isset($_POST['submit']) && strlen($_POST['search']) > 1) {
  18.  
  19. $searchq = $_POST['search'];
  20. $data = array();
  21.  
  22. $sql = "SELECT * FROM `movie-info` WHERE `keywords` LIKE :keyword"; // SQL-kysely
  23. $stmt = $pdo->prepare($sql);
  24.  
  25. // Suoritetaan SQL-kysely
  26. $stmt->execute(array(
  27. 'keyword' => '%' . $_POST['search'] . '%'
  28. ));
  29.  
  30. // Ei hakutuloksia
  31. if($stmt->rowCount() == 0) {
  32. echo 'There is no search results!';
  33. exit();
  34.  
  35. // Jos tuloksia
  36. } else {
  37.  
  38. $i = 0;
  39.  
  40. $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
  41.  
  42. foreach($results as $row) {
  43.  
  44. // Tallennetaan data -taulukkoon, omalla tietokannan id arvollaan
  45. $output = '<div id="title">'.$row['title'].'</div>';
  46. $output .= '<div id="description">'.$row['description'].'</div>';
  47. $output .= '<div id="info">
  48. '.$row['genre'].'<br>
  49. '.$row['imdb'].'<br>
  50. '.$row['actors'].'<br>
  51. '.$row['playtime'].'
  52. </div>';
  53. echo $output;
  54. }
  55.  
  56. }
  57. }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement