SELECT
products.productName,
products.prodID,
products.novelties,
products.superSale,
products.bestseller,
products.retailPrice,
products.baseRetailPrice,
products.vendorID,
SUM(product_offers.stock) AS totalStock
FROM
products
LEFT JOIN
product_offers ON products.prodID = product_offers.prodID
WHERE products.prodCountry = 'США'
GROUP BY
products.productName,
products.prodID,
products.novelties,
products.superSale,
products.bestseller,
products.retailPrice,
products.baseRetailPrice,
products.vendorID
ORDER BY
totalStock = 0, -- Sorting by totalStock equal to 0 (0 will be at the end)
products.productName -- You can change this to another field for a different sorting criterion
LIMIT 12 OFFSET 0 -- Applying LIMIT and OFFSET for pagination
Ошибка mysqli: 1247 : Reference 'totalStock' not supported (reference to group function)
Fatal error: Uncaught TypeError: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool given in /var/www/domainspay/data/www/xrbrands.ru/application/controllers/controller_country.php:406
Stack trace:
#0 /var/www/domainspay/data/www/xrbrands.ru/application/controllers/controller_country.php(406): mysqli_num_rows(false)
#1 /var/www/domainspay/data/www/xrbrands.ru/application/controllers/controller_country.php(66): Controller_country->getProducts('\xD0\xA1\xD0\xA8\xD0\x90', 12, 0)
#2 /var/www/domainspay/data/www/xrbrands.ru/application/core/route.php(131): Controller_country->action_index()
#3 /var/www/domainspay/data/www/xrbrands.ru/application/core/route.php(85): Route::callAction(Object(Controller_country), 'action_index')
#4 /var/www/domainspay/data/www/xrbrands.ru/application/bootstrap.php(130): Route::start()
#5 /var/www/domainspay/data/www/xrbrands.ru/index.php(13): include('/var/www/domain...')
#6 {main}
thrown in /var/www/domainspay/data/www/xrbrands.ru/application/controllers/controller_country.php on line 406