我在opencart上工作,并使用下面提到的查询获取产品列表,这些产品在顶部显示最新的产品。
$result = mysqli_query($con,"select p.image,p.price,p.store_name,p.deal_title_url,p.shop_now_url,p.coupon_code,p.special_deal_txt,p.special_comment_txt,s.price,d.name,p.date_added from oc_product p, oc_product_special s,oc_product_description d where p.product_id=s.product_id and p.product_id=d.product_id order by p.date_added DESC $limit;");注- 1.限制用于分页2.从多个表取数据
现在我想在显示屏的顶部展示所有的特色产品。因此,基本上,特色数组中的产品必须始终显示在顶部,然后根据创建日期显示其余产品。
特色产品id保存在数组中- $featured_array
如何做到这一点?
请注意,特色产品的数量可能有所不同。
发布于 2015-01-24 06:26:05
尝试使用UNION。在第一个查询中获取特色产品,在第二个查询中放入当前查询。Limit适用于联合结果
(
select p.image,p.price,p.store_name,p.deal_title_url,p.shop_now_url,p.coupon_code,p.special_deal_txt,p.special_comment_txt,s.price,d.name,p.date_added from oc_product p, oc_product_special s,oc_product_description d where p.product_id=s.product_id and p.product_id=d.product_id AND p.product_id IN($featuredProductsIds) order by p.date_added DESC
)
UNION
(
select p.image,p.price,p.store_name,p.deal_title_url,p.shop_now_url,p.coupon_code,p.special_deal_txt,p.special_comment_txt,s.price,d.name,p.date_added from oc_product p, oc_product_special s,oc_product_description d where p.product_id=s.product_id and p.product_id=d.product_id order by p.date_added DESC
)
$limit;https://stackoverflow.com/questions/28119344
复制相似问题