gpt4 book ai didi

php - mysql 查询不断返回重复的结果

转载 作者:行者123 更新时间:2023-11-30 01:30:33 25 4
gpt4 key购买 nike

我有一个返回重复结果的查询。这是:

$product_sql_test2 = $this->db->query("SELECT p.product_id, p.price,    pc.product_id AS product_id
FROM oc_product p
INNER JOIN oc_product_to_category pc ON p.product_id = pc.product_id
WHERE p.price BETWEEN '".$product_info['related_kv4nt_min_2']."' and '".$product_info['related_kv4nt_max_2']."'
AND pc.category_id = '".$product_info['related_kv4nt_id_2']."'
GROUP BY pc.product_id
ORDER BY RAND( )
LIMIT 0 , 10");

我尝试使用 array_unique 函数,但它没有做任何事情。可以做什么?

P.s.我以前问过类似的问题,但没有得到答案,链接是: previous question with full source code.

致以诚挚的问候博格丹

p.p.s。现在源代码

if(isset($product_info['related_kv4nt_id_2'])) 
{
$i=1;
$imax = 5;
while ($i < $imax)
{
$product_sql_test2 = $this->db->query("SELECT DISTINCT p.product_id, p.price, pc.product_id AS product_id
FROM oc_product p
INNER JOIN oc_product_to_category pc ON p.product_id = pc.product_id
WHERE p.price BETWEEN '".$product_info['related_kv4nt_min_2']."' and '".$product_info['related_kv4nt_max_2']."'
AND pc.category_id = '".$product_info['related_kv4nt_id_2']."'
GROUP BY pc.product_id
ORDER BY RAND( )
LIMIT 0 , 10");
if(isset($product_sql_test2->row['product_id']))
{
$this->data['product_spec_2_'.$i.''] = $product_sql_test2->row['product_id'];
}
$i++;
}
}

最佳答案

尝试在 select 语句中添加 DISTINCT 子句 http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html

关于php - mysql 查询不断返回重复的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17522464/

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