Reputation: 16296
I have to make an SQL command that look for a String in the database table that match one of the strings containing in my array.
//this is my array
$liste_des_themes=array("Préfectures et sous-préfectures","Mairie","Banque");
$stmt = $this->db->prepare('SELECT * FROM etablissements where type IN $liste_des_themes');//i tried this but seems not working
$stmt->execute();
$stmt->bind_result($id, $libelle);
while ($stmt->fetch()) {
echo "$id $libelle<br/>";
}
$stmt->close();
Upvotes: 0
Views: 59
Reputation: 146360
You need to create an IN
list in the correct format:
$liste_des_themes=array("Préfectures et sous-préfectures","Mairie","Banque");
$in_list = "'".implode("','", $liste_des_themes)."'";
$stmt =
$this->db->prepare('SELECT * FROM etablissements where type IN ('.$in_list.')');
Upvotes: 5