Answer the question
In order to leave comments, you need to log in
How to use several cases at once when pressing several buttons?
Good afternoon, I have the following form of sorting on the site:
if(!empty($filter['sort'])) {
switch ($filter['sort']) {
// В наличии
case 'in_cat_stock':
$order = "(SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.price>0 AND (pv.stock>0) LIMIT 1) DESC";
break;
case 'in_cat_stock_desc':
$order = "(SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.price>0 AND (pv.stock<0) LIMIT 1) DESC";
break;
//Со скидкой
case 'in_cat_sale':
$order = '(SELECT pv.compare_price-pv.price FROM __variants pv WHERE pv.product_id=p.id AND pv.price>0 AND pv.position=(SELECT MIN(position) FROM __variants WHERE product_id=p.id LIMIT 1) LIMIT 1) DESC';
break;
case 'in_cat_sale_desc':
$order = '(SELECT pv.compare_price-pv.price FROM __variants pv WHERE pv.product_id=p.id AND pv.price<0 AND pv.position=(SELECT MIN(position) FROM __variants WHERE product_id=p.id LIMIT 1) LIMIT 1) DESC';
break;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question