Salve a tutti!
Ho una tabella "articolo" in cui è presente un campo "chiave".
Ho bisogno di una select che cerchi all'interno di quel campo prendendo i dati da un array.
Ho provato in questo modo:
Però mi da questo tipo di errore:
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 '%economia% OR chiave LIKE %mercati% OR chiave LIKE %nazionali% OR chiave LIKE %s' at line 1
Mi sapreste aiutare?
Ho una tabella "articolo" in cui è presente un campo "chiave".
Ho bisogno di una select che cerchi all'interno di quel campo prendendo i dati da un array.
Ho provato in questo modo:
PHP:
$key = "economia, mercati, nazionali, sviluppo, efficienza";
$key = str_replace(" ", "", $key);
$key = explode(",",$key);
foreach($key as $keys){
$sql_ric[] = 'chiave LIKE %'.$keys.'%';
}
$sql_ric = 'SELECT * FROM articoli WHERE '.implode(" OR ", $sql_ric) or die(mysql_error());
$risultato = mysql_query($sql_ric, $con) or die(mysql_error());
while($riga_ric = mysql_fetch_object($risultato)){
echo $riga_ric->titolo;
}
Però mi da questo tipo di errore:
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 '%economia% OR chiave LIKE %mercati% OR chiave LIKE %nazionali% OR chiave LIKE %s' at line 1
Mi sapreste aiutare?