gpt4 book ai didi

php - 在显示屏顶部显示特色产品

转载 作者:行者123 更新时间:2023-11-29 23:10:08 24 4
gpt4 key购买 nike

我正在使用 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

如何做到这一点?

请注意,特色产品的数量可能会有所不同。

最佳答案

尝试使用 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 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;

关于php - 在显示屏顶部显示特色产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28119344/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com