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.*, atts.*, pij2.thefile from prodcat_weight inner join products on products.prod_id=prodcat_weight.prod_id left join (select product_id, min(price) as pricefrom, count(*) as attcount from products_atts group by product_id) as atts on products.id=atts.product_id left join (SELECT products_images.filename as thefile, products_images.prod_id FROM `products_images` join (SELECT min(weight) as lweight, prod_id FROM `products_images` group by prod_id ) as pij on (pij.prod_id, pij.lweight) = (products_images.prod_id, products_images.weight) group by prod_id) as pij2 on products.prod_id=pij2.prod_id WHERE prodcat_weight.cat_id='16' and prodcat_weight.hidden='0' order by prodcat_weight.weight ASC, id desc LIMIT -12, 12