Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- $dsn = 'mysql:dbname=movies;host=127.0.0.1';
- $user = 'root';
- $password = '';
- // Yhteyden muodostus
- try {
- $pdo = new PDO($dsn, $user, $password); // Uusi PDO objekti
- } catch (PDOException $e) {
- echo 'Connection failed: ' . $e->getMessage();
- }
- if(isset($_POST['submit']) && strlen($_POST['search']) > 1) {
- $searchq = $_POST['search'];
- $data = array();
- $sql = "SELECT * FROM `movie-info` WHERE `keywords` LIKE :keyword"; // SQL-kysely
- $stmt = $pdo->prepare($sql);
- // Suoritetaan SQL-kysely
- $stmt->execute(array(
- 'keyword' => '%' . $_POST['search'] . '%'
- ));
- // Ei hakutuloksia
- if($stmt->rowCount() == 0) {
- echo 'There is no search results!';
- exit();
- // Jos tuloksia
- } else {
- $i = 0;
- $results = $stmt->fetchAll(PDO::FETCH_ASSOC);
- foreach($results as $row) {
- // Tallennetaan data -taulukkoon, omalla tietokannan id arvollaan
- $output = '<div id="title">'.$row['title'].'</div>';
- $output .= '<div id="description">'.$row['description'].'</div>';
- $output .= '<div id="info">
- '.$row['genre'].'<br>
- '.$row['imdb'].'<br>
- '.$row['actors'].'<br>
- '.$row['playtime'].'
- </div>';
- echo $output;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement