generated from francesco/deploy-dinamico
This commit is contained in:
122
file/search/index.php
Normal file
122
file/search/index.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
if (isset($_GET['s'])) {
|
||||
highlight_file("index.php");
|
||||
return;
|
||||
}
|
||||
|
||||
// Ricerca film dal DB
|
||||
|
||||
$conn = mysqli_connect("localhost", "root", "", "film_attori");
|
||||
|
||||
if ($conn === false) {
|
||||
exit("<code>Errore: impossibile stabilire una connessione " . mysqli_connect_error() . "</code>");
|
||||
}
|
||||
|
||||
// Collegamento al DB effettuato
|
||||
|
||||
$query = "SELECT film.id_film, film.nome, film.trama, film.data_uscita, generi.nome as genere FROM film, generi WHERE film.id_genere = generi.id_genere ORDER BY film.data_uscita";
|
||||
$searched = "";
|
||||
|
||||
// Leggo la ricerca
|
||||
if (isset($_GET['q'])) {
|
||||
if (is_string($_GET['q']) && $_GET['q'] !== "" && $_GET['q'] !== null) {
|
||||
$nome = htmlspecialchars($_GET['q']);
|
||||
$searched = $nome;
|
||||
$query = "SELECT film.id_film, film.nome, film.trama, film.data_uscita, generi.nome as genere FROM film, generi WHERE film.id_genere = generi.id_genere AND film.nome LIKE '%" . $nome . "%' ORDER BY film.data_uscita";
|
||||
}
|
||||
}
|
||||
|
||||
// Leggo i dati del film e faccio il JOIN per avere il nome del genere
|
||||
$res = mysqli_query($conn, $query);
|
||||
|
||||
if ($res === false) {
|
||||
// Codice HTTP 500: Errore
|
||||
http_response_code(500);
|
||||
echo "<code>Errore: impossibile eseguire la query. " . mysqli_error($conn) . "</code>";
|
||||
mysqli_close($conn);
|
||||
exit();
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="it">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Film - The NoSpace Cinema</title>
|
||||
<!--- www.francescomancuso.it -->
|
||||
<link rel="stylesheet" href="../style.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<div class="container">
|
||||
<a href="../" style="text-decoration: none;">
|
||||
<div>
|
||||
<img src="../logo.png">
|
||||
<h4>The NoSpace Cinema</h4>
|
||||
</div>
|
||||
</a>
|
||||
<div>
|
||||
<a href=".?s" style="font-size:16px">Vedi sorgente pagina</a>
|
||||
<a href="../search/" class="button">Tutti i film</a>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div class="container">
|
||||
<div class="hero search">
|
||||
<h1>Film in sala</h1>
|
||||
<form action="." method="GET">
|
||||
<fieldset>
|
||||
<input type="text" id="query" name="q" value="<?php echo $searched; ?>" placeholder="Scrivi il titolo...">
|
||||
<button type="submit">Cerca</button>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="page">
|
||||
<div class="container">
|
||||
<div class="grid films">
|
||||
<?php
|
||||
|
||||
$test = true;
|
||||
|
||||
while ($row = mysqli_fetch_array($res)) {
|
||||
$test = false;
|
||||
?>
|
||||
<a href="<?php echo "../film?id=" . $row['id_film']; ?>">
|
||||
<div class="film">
|
||||
<img src="<?php echo "../api/v1/img/?n=" . urlencode($row['nome'] . ' ' . date('Y', strtotime($row['data_uscita']))); ?>">
|
||||
<h5><?php echo $row['nome']; ?></h5>
|
||||
<div class="genere">
|
||||
<?php echo $row['genere']; ?>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
<?php
|
||||
}
|
||||
|
||||
mysqli_free_result($res);
|
||||
mysqli_close($conn);
|
||||
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
// Nessun risultato...
|
||||
if ($test) {
|
||||
echo "<div class=\"container text-center\">Nessun risultato trovato!</div>";
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="container">
|
||||
<span>Realizzato da Francesco Giuseppe Mancuso - classe 5E - www.francescomancuso.it</span>
|
||||
</div>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user