I have written a query for use in a Prestashop 1.6 module and was surprised to see that LIMIT
doesn’t work in the query. The plan is to get the top 10 best seller products.
I have tested it in phpMyAdmin and it works perfectly, but when in the application it doesn’t work. Following is the query.
$sql = 'SELECT id_product, sale_nbr
FROM '._DB_PREFIX_.'product_sale
WHERE id_product = '.(int)$id_product.'
ORDER BY sale_nbr DESC LIMIT 10';
return Db::getInstance()->executeS($sql);
I have also tried LIMIT 0, 10
There are no error messages the LIMIT
is simply not working. In my test example 15 of the 50 products in my list are top sellers, but I want only 10 of them to show, but it always comes out as 15.
3
Answers
perhaps try nesting:
It all depends on what you use to execute your query.
Using:
With the 3rd way you should be able to use the limit; More info here : https://www.prestashop.com/fr/blog/les-bonnes-pratiques-de-la-classe-db-sur-prestashop-1-5
Regards,
To get top 10 best seller products :