You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-12, 12' at line 1
query=SELECT products.*, min(products_atts.price) as pricefrom, count(products_atts.product_id) as attcount, products_images.filename as thefile from prodcat_weight inner join products on products.prod_id=prodcat_weight.prod_id left join products_atts on products.id=products_atts.product_id left join products_images on products.prod_id=products_images.prod_id and products_images.firstimg=1 WHERE prodcat_weight.cat_id IN (813, 821, 840, 837, 838, 841, 889, 814, 839, 907, 820, 877, 829, 833, 835, 875, 855, 856, 857, 830, 843, 845, 842, 927, 934, 950, 817, 832, 900, 846, 844, 836, 903, 901, 937, 938, 952) and prodcat_weight.hidden='0' group by products.id order by prodcat_weight.weight ASC, id desc LIMIT -12, 12