Error Number: 1064

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 '-21, 21' at line 11

SELECT `tovars`.`id`, `tovars`.`alias`, `tovars`.`category_id`, `tovars`.`title_ru` as `title`, `pictures`.`title_ru` as `picture_title`, `products`.`price`, `products`.`price_sale`, `painter_users`.`name` as `author_name`, `painter_users`.`id` as `author_id`, `painter_users`.`alias` as `author_alias`, CASE WHEN tovars_images.name is not null THEN tovars_images.name ELSE (SELECT name FROM tovars_images WHERE tovars_images.tovar_id = tovars.id AND tovars_images.product_image_id = (SELECT id FROM products_images WHERE products_images.product_id = tovars.product_id ORDER BY products_images.main desc, products_images.sort asc LIMIT 1 ) LIMIT 1) END as photo_name, CASE WHEN tovars_images.type is not null THEN tovars_images.type ELSE (SELECT type FROM tovars_images WHERE tovars_images.tovar_id = tovars.id AND tovars_images.product_image_id = (SELECT id FROM products_images WHERE products_images.product_id = tovars.product_id ORDER BY products_images.main desc, products_images.sort asc LIMIT 1 ) LIMIT 1) END as photo_type, `tovars`.`active`, (SELECT COUNT(likes.tovar_id) FROM likes WHERE likes.tovar_id = tovars.id) as likes FROM `tovars` LEFT JOIN `products` ON `products`.`id` = `tovars`.`product_id` INNER JOIN `pictures` ON `pictures`.`id` = `tovars`.`picture_id` LEFT JOIN `painter_users` ON `painter_users`.`id` = `pictures`.`master_id` LEFT JOIN tovars_images ON tovars_images.tovar_id = tovars.id AND tovars_images.product_image_id = (SELECT id FROM products_images WHERE products_images.product_id = tovars.product_id ORDER BY products_images.main desc, products_images.sort asc LIMIT 1 ) WHERE `tovars`.`id` IN(3771,3792,4275,4296,4317,4338,4359,4380,4401,4422,4443,4464,4485,4506,4527,4548,4569,4590,4611,4632,4653,4674,4695,4716,4737,4758,4779,4800,4821,4842,4863,4884,4905,4926,4947,4968,4989,5010,5031,5052,5073,5094,5115,5136,5157,5178,5199,5220,5241,5262,5283,5304,5325,5346,5367,5388,5409,5430,5451,5472,5514,5535,5577,5598,5619,5640,5661,5682,5703,5724,5745,5766,5787,5808,5829,5850,5871,5892,5913,5934,5955,5976,5997,6018,6039,6060,6081,6102,6123,6144,6165,6186,6207,6228,6249,6270,6291,6312,6333,6354,6375,6396,6417,6438,6459,6564,6585,6606,6648,6669,6690,6711,6732,6753,6774,6795,6816,6837,6858,6933,6959,6980,7016,7035,7056,7077,7098,7119,7141,7160,7184,7194,7215,7231,7252,7265,7275,7296,7311,7332,7353,7374,7395,7433,7453,7475,7488,7498,7538,7567,7577,7587,7599,7631,7652,7671,7689,7699,7718,7738,7750,7760,7787,7841,7860,7870,7886,7907,7928,7949,7960,7977,7992,8034,8044,8071,8092,8113,8134,8177,8206,8222,8253,8274,8287,8308,8413,8423,8447,8468,8489,8510,8531,8552,8573,8594,8615,8636,8648,8661,8682,8724,8748,8774,8795,8805,8817,8838,8856,8877,8898,8919,8931,9018,9031,9072,9085,9111,9138,9159,9180,9201,9222,9243,9263,9305,9347,9357,9383,9404,9446,9467,9479,9500,9559,9589,9602,9631,9657,9683,9698,9714,9730,9746,9756,9821,9840,9908,9974,10052,10065,10078,10092,10105,10118,10131,10143,10155,10168,10181,10197,10227,10248,10263,10302,10314,10333,10359,10374,10405,10418,10431,10444,10457,10470,10483,10514,10534,10544,10556,10566,10591,10604,10617,10630,10642,10652,10662,10672,10685,10695,10708,10726,10744,10766,10776,10789,10801,10822,10840,10899,10923,10943,10959,10984,11005,11025,11066,11087,11108,11129,11150,11172,11204,11236,11257,11270,11291,11312,11333,11354,11375,11396,11406,11500,11532,11553,11574,11594,11615,11636,11657,11678,11696,11717,11727,11740,11753,11763,11784,11794,11805,11820,11836,11889,11911,11932,11950,11960,11974,11990,12000,12012,12024,12037,12049,12062,12075,12091,12104,12123,12133,12154,12175,12194,12215,12236,12266,12287,12297,12311) ORDER BY `tovars`.`flag_action` desc, `likes` DESC, `tovars`.`id` asc LIMIT -21, 21

Filename: models/Tovar_model.php

Line Number: 258