OK it is solved.
$sql="select sum(product.quantity) as prod_quantity from sales group by product_code order by prod_quantity"; is not working
But,
$sql="select sum(product.quantity) as prod_quantity from sales group by product_code order by sum(product.quantity)"; is working.
I thought it was the same, but it is not. Anyone knows why? Thanks!