Hallo miteinander!
Ich habe hier eine funktionierende Suchfunktion das aber nur mit vollständig ausgefüllten Feldern bei der Suchabfrage funktioniert.
Suchformular:
Abfrage & Ausgabe:
Wenn man zum Beispiel beim Input "Attore" Jonny Depp eingibt werden alle Datensätze ausgegeben die bei dieser Spalte dieser genaue Wert enthaltet.
Was aber nicht funktionert ist das wenn man nur Jonny darin eingibt, wird überhaupt nichts ausgegeben, bzw. nur das:
Ich habe darum recherchiert und gelesen man soll vor und nach der Variabel die % Zeichen einsetzen damit eine "Fragmentsuche" darin gewährleistet wird.
Mit folgenden Anpassungen habe ich es probiert, dan wird aber auch wieder nichts ausgegeben:
Hier bei einer der Select Abfragen:
Diese Varianten haben bei mir nicht funktioniert. Was mache ich falsch?
Danke für die Feedbacks!
Ich habe hier eine funktionierende Suchfunktion das aber nur mit vollständig ausgefüllten Feldern bei der Suchabfrage funktioniert.
Suchformular:
HTML Code:
<form id="cercare" method="POST" action="cercato.php" enctype="multipart/form-data"> <label for="titolo">Titolo</label> <input type="text" name="titolo" id="titolo" /> <label for="lingua">Lingua</label> <select name="lingua" id="lingua"> <option></option> <option>Italiano</option> <option>Tedesco</option> </select> <label for="genere">Genere</label> <select name="genere" id="genere"> <option></option> <option>Azione</option> <option>Since Fiction</option> <option>Fantasia</option> <option>Commedia</option> <option>Amore</option> <option>Drama</option> <option>Horror</option> </select> <label for="attore1">Attore 1</label> <input type="text" name="attore1" id="attore1" /> <label for="attore2">Attore 2</label> <input type="text" name="attore2" id="attore2" /> <label for="anno">Anno</label> <input type="text" name="anno" id="anno" /> <label for="tipo_disco">Tipo Disco</label> <select name="tipo_disco" id="tipo_disco"> <option></option> <option>Blu-Ray</option> <option>DVD</option> <option>DivX</option> </select> <label for="divx">Qualià DivX</label> <select name="divx" id="divx"> <option></option> <option>Alta</option> <option>Media</option> <option>Bassa</option> </select> <label for="visto_amedeo">Visto Amedeo</label> <select name="visto_amedeo" id="visto_amedeo"> <option></option> <option>Si</option> <option>No</option> </select> <label for="visto_fabian">Visto Fabian</label> <select name="visto_fabian" id="visto_fabian"> <option></option> <option>Si</option> <option>No</option> </select> <label for="visto_gerardina">Visto Gerardina</label> <select name="visto_gerardina" id="visto_gerardina"> <option></option> <option>Si</option> <option>No</option> </select> <label for="commento">Commento</label> <input type="text" name="commento" id="commento" /> <input type="submit" class="submit" name="submit" value="Cerca" /> </form>
PHP Code:
<?php
//Verbindung zur Datenbank herstellen.
$server = "***";
$user = "***";
$pw = "***";
$verdindung_server = mysql_connect ("$server", "$user", "$pw") or die ("connection failed");
mysql_select_db ("film_db") or die ("no database");
?>
<?php
$titolo = $_POST['titolo'];
$lingua = $_POST['lingua'];
$genere = $_POST['genere'];
$attore1 = $_POST['attore1'];
$attore2 = $_POST['attore2'];
$anno = $_POST['anno'];
$tipo_disco = $_POST['tipo_disco'];
$divx = $_POST['divx'];
$visto_amedeo = $_POST['visto_amedeo'];
$visto_fabian = $_POST['visto_fabian'];
$visto_gerardina = $_POST['visto_gerardina'];
$commento = $_POST['commento'];
?>
<table>
<?php
$abfrage = "SELECT * FROM Filme WHERE 1 ".
(!empty($titolo) ? "AND Titolo = '$titolo'" : '').
(!empty($lingua) ? "AND Lingua = '$lingua'" : '').
(!empty($genere) ? "AND Genere = '$genere'" : '').
(!empty($attore1) ? "AND Attore_1 = '$attore1'" : '').
(!empty($attore2) ? "AND Attore_2 = '$attore2'" : '').
(!empty($anno) ? "AND Anno = '$anno'" : '').
(!empty($tipo_disco) ? "AND Tipo_disco = '$tipo_disco'" : '').
(!empty($divx) ? "AND DivX = '$divx'" : '').
(!empty($visto_amedeo) ? "AND Visto_Amedeo = '$visto_amedeo'" : '').
(!empty($visto_fabian) ? "AND Visto_Fabian = '$visto_fabian'" : '').
(!empty($visto_gerardina) ? "AND Visto_Gerardina = '$visto_gerardina'" : '').
(!empty($commento) ? "AND Commento = '$commento'" : '');
$ergebnis = mysql_query($abfrage);
while($row = mysql_fetch_object($ergebnis))
{
echo "<tr><td><p class=fett>ID</p><p>$row->id</p></td>";
echo "<td><p class=fett>Locandina</p><p><a href=uploads/$row->Immagine rel=lytebox><img src=uploads/$row->Immagine /></a></p></td>";
echo "<td><p class=fett>Titolo</p><p>$row->Titolo</p></td>";
echo "<td><p class=fett>Lingua</p><p>$row->Lingua</p></td>";
echo "<td><p class=fett>Genere</p><p>$row->Genere</p></td>";
echo "<td><p class=fett>Attore 1</p><p>$row->Attore_1</p></td>";
echo "<td><p class=fett>Attore 2</p><p>$row->Attore_2</p></td>";
echo "<td><p class=fett>Anno</p><p>$row->Anno</p></td>";
echo "<td><p class=fett>Media</p><p>$row->Tipo_disco</p></td>";
echo "<td><p class=fett>Qualità DivX</p><p>$row->DivX</p></td>";
echo "<td><p class=fett>Visto Amedeo</p><p>$row->Visto_Amedeo</p></td>";
echo "<td><p class=fett>Visto Fabian</p><p>$row->Visto_Fabian</p></td>";
echo "<td><p class=fett>Visto Gerardina</p><p>$row->Visto_Gerardina</p></td>";
echo "<td><p class=fett>Commento</p><p>$row->Commento</p></td></tr>";
}
?>
</table>
Was aber nicht funktionert ist das wenn man nur Jonny darin eingibt, wird überhaupt nichts ausgegeben, bzw. nur das:
HTML Code:
<table></table>
Mit folgenden Anpassungen habe ich es probiert, dan wird aber auch wieder nichts ausgegeben:
Hier bei einer der Select Abfragen:
PHP Code:
(!empty($attore1) ? "AND Attore_1 = '%$attore1%'" : '').
PHP Code:
(!empty($attore1) ? "AND Attore_1 = %'$attore1'%" : '').
PHP Code:
(!empty($attore1) ? "AND Attore_1 = '%%$attore1%%'" : '').
Danke für die Feedbacks!
Comment