I have a array stored in $_POST['extras'] and when I implode it to a string which the result could be something like "1,4" it makes bugging my Mysql prepared query
For instance this doesn't works (only first row returned)
if(isset($_POST['extras'])){
$string_extras = implode(",", $_POST['extras']);
var_dump($_POST['extras']);
//display : array(2) { [0]=> string(1) "1" [1]=> string(1) "4" } in my case !
var_dump($string_extras);
//display : string(3) "1,4" in my case !
$req7 = $DB->query('SELECT * FROM `Option_extra_PT` WHERE `id_option_extra` IN(:post_extras)');
$req7->bindParam(':post_extras', $string_extras);
$req7->execute();
// While loop
while ($data_req7 = $req7->fetch(PDO::FETCH_ASSOC)) {
//Display result of Query
echo ' <div class="extra_Bit">
<div class="extra_libelle"><label>(ref. '.$data_req7['id_option_extra'].')'.$data_req7['nom_option_extra'].'</label></div>
<div class="extra_prix">'.$data_req7['prix_option_extra'].' €</div>
<div class="clearfix"></div>
</div>';
//for me only the first row is returned !
}
}
And this works properly (but don't suit me because the result of $_POST won't be always the same of course... and can't be replace by the value 1,4) :
$req7 = $DB->query('SELECT * FROM `Option_extra_PT` WHERE `id_option_extra` IN(1,4)');
// While loop
while ($data_req7 = $req7->fetch(PDO::FETCH_ASSOC)) {
//Display result of Query
echo ' <div class="extra_Bit">
<div class="extra_libelle"><label>(ref. '.$data_req7['id_option_extra'].')'.$data_req7['nom_option_extra'].'</label></div>
<div class="extra_prix">'.$data_req7['prix_option_extra'].' €</div>
<div class="clearfix"></div>
</div>';
//for me this works perfectly !
}