Ich habe mir eine Suchfunktion gebaut, die auch mehrere Suchwörter unterstüzt. Doch komischerweise bricht er immer mit einem mysql-error ab.
Hier mal mein Quellcode der suchfunktion.
PHP-Code:
<?php
$suchwort = explode(" ",$_GET['q']);
$swneu = "";
foreach( $suchwort as $element ) {
$swneu = $swneu."motd_motd LIKE '%$element%' OR
motd_autor LIKE '%$element%' OR
motd_keys LIKE '%$element%' ";
}
$where = $swneu." AND motd_allow = '1' ";
$select = "SELECT motd_id, motd_motd FROM page_motd WHERE $where ORDER BY motd_autor";
$select = mysql_query($select) or die(mysql_error());
?>
Hier ist der Query-String:
Code:
SELECT motd_id, motd_motd FROM page_motd WHERE motd_motd LIKE '%Bla%' OR motd_autor LIKE '%Bla%' OR motd_keys LIKE '%Bla%' motd_motd LIKE '%blub%' OR motd_autor LIKE '%blub%' OR motd_keys LIKE '%blub%' AND motd_allow = '1' ORDER BY motd_autor
Dazu die Fehlermeldung, aus der ich nicht schlau werde
Code:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'motd_motd LIKE '%blub%' OR motd_autor LIKE '%blub%'
Der Fehler tritt allerdings nur auf, wenn nach mehreren Wörtern gesucht wird.
Bei nur einem Suchwort funktioniert alles Reibungslos.