Bonjour,
Je ne trouve pas d'exemple pour préparer ma requête :
$stmt = $con -> prepare ( "SELECT * FROM products
WHERE published = 'Yes'
AND category IN ='dresses, skirts'
AND color IN 'blue, pink, yellow'
AND price BETWEEN '10' AND '15'
ORDER by price ASC, BY new DESC ");
Un lien vers un tutoriel ou un cours, ou un sujet similaire résolu
Je ne sais pas faire, vu que je n'ai pas d'exemple, ou seulement pour 1 seule WHERE IN clause.
if (isset($_POST['action']))
{
$published='Y';
$sort_products = mysql_query ( "select * from products where published =".$published." ");
if ( isset ($_POST['product_category']))
{ $array= $_POST['product_category'];
$product_category = implode(',', array_fill(0, count($array), '?')); // creates a string containing ?,?,?
$sort_products .= "AND p_cat_id IN (". $product_category." ) ";
call_user_func_array(array($sort_products, 'bind_param'), $params_category);
}
if ( isset ($_POST['product_brand']))
{ $array= $_POST['product_brand'];
$product_brand = implode(',', array_fill(0, count($array), '?')); // creates a string containing ?,?,?
$array[] = $this->getTime();
$types = str_repeat('i', count($array));
$params_brand = array($types);
foreach ($array as $key => $value)
{ $params_brand[] = &$array[$key];
}
$sort_products .= "AND product_brand IN (". $product_brand." ) ";
call_user_func_array(array($sort_products, 'bind_param'), $params_brand);
}
// etc j'ai plein d'autres if ( isset ($_POST['']))
// Où et comment associer mes multiples call_user_func_array(array($sort_products, 'bind_param'), $params_category); précédés d'1 WHEREpublished = ? et suivis de ORDER by ?
if(!$sort_products->execute()) { trigger_error('Invalid query : ' . $con->error); }
$res = $sort_products->get_result();