我在Zen购物车中尝试创建连接和计数(然后按它设置顺序)时遇到了很多麻烦。
以下是代码:
echo $listing_sql = "select " . $select_column_list . " p.products_id, count(opc.products_id), p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status =1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p2c.products_id = s.products_id
join " . TABLE_ORDERS_PRODUCTS . " opc on opc.products_id = p.products_id
where p.products_status = 1
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p2c.categories_id = '" . (int)$current_category_id . "'" .
$alpha_sort . " ORDER BY count(opc.products_id)";
我想计算opc.products_id,然后在结尾处将其设置为ORDER BY count(opc.products_id)。不知道我哪里出错了,非常感谢!
科斯塔
答案 0 :(得分:0)
很难不丢失代码,但是你需要做的事情:
1)创建一个查询,选择您想要的产品,只需不计数(opc.products_id)并立即进行排序。测试一下。所有产品每个应该只有一行(没有两面性),然后......
2)编辑代码,重点关注这三个突出显示的部分:
echo $listing_sql = "select " . $select_column_list . " p.products_id, count(opc.products_id), p.products_type, p.master_categories_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description, IF(s.status = 1, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status =1, s.specials_new_products_price, p.products_price) as final_price, p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
,count(opc.products_id) as opc_count
from " . TABLE_PRODUCTS_DESCRIPTION . " pd, " .
TABLE_PRODUCTS . " p left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id, " .
TABLE_PRODUCTS_TO_CATEGORIES . " p2c left join " . TABLE_SPECIALS . " s on p2c.products_id = s.products_id
join " . TABLE_ORDERS_PRODUCTS . " opc on opc.products_id = p.products_id
where p.products_status = 1
and p.products_id = p2c.products_id
and pd.products_id = p2c.products_id
and pd.language_id = '" . (int)$_SESSION['languages_id'] . "'
and p2c.categories_id = '" . (int)$current_category_id . "'" .
$alpha_sort . "
GROUP BY p.products_id ORDER BY opc_count ";