I have this query that fills an array:
SELECT producto.*, imagen_producto.nombre_archivo
FROM producto_categoria_web, producto
LEFT JOIN imagen_producto
ON producto.ID = imagen_producto.producto_ID
AND imagen_producto.size LIKE 'small'
WHERE producto.estado=1
and producto_categoria_web.producto_ID=producto.ID
and producto_categoria_web.categoria_web_ID=" . $categoria_web_ID . "
and (producto.visible_web!='NO' or ISNULL(producto.visible_web))
ORDER BY nombre,stock_actual DESC
I don't know if I will be able to order it by the query or if I need to do something to the array.
In order for the out-of-stock items to remain at the end of the list regardless of their status,
nombre
you should sort by the rule that defines whether that item is in stock or not (stock_actual > 0
).In the articles that are out of stock , it
stock_actual > 0
will be worth0
, staying for the end, while the rest (regardless of the quantity in stock) the value ofstock_actual > 0
is1
appearing first, and each block ordered bynombre
in the second level.Here is the SQL query you should use: