gpt4 book ai didi

mysql - SQL 不只显示一种产品,而是显示更多产品

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

            $query_sub = "SELECT * FROM `product_mappings` LEFT JOIN `product_list` ON `product_mappings`.ID_PRODUCT =`product_list`.ID  WHERE ID_USER='" . $row{'ID'} . "'";
$result_sub = mysql_query($query_sub);
if ($result_sub && mysql_num_rows($result_sub) > 0)
{
$data_products = array();
while ($row_sub = mysql_fetch_array($result_sub))
{
$data_sub = array();
$data_sub["ID"] = $row_sub{'ID'};
$data_sub["product"] = $row_sub{'PRODUCT'};


$query_sub_unactive = "SELECT * FROM `product_list` WHERE ID != '" . $row_sub{'ID'} . "' ";
$result_sub_unactive = mysql_query($query_sub_unactive);
if ($result_sub_unactive && mysql_num_rows($result_sub_unactive) > 0)
{
$data_products_unactive = array();
while ($row_sub_unactive = mysql_fetch_array($result_sub_unactive))
{
$data_sub_unactive = array();
$data_sub_unactive["ID"] = $row_sub_unactive{'ID'};
$data_sub_unactive["productss"] = $row_sub_unactive{'PRODUCT'};


array_push($data_products_unactive, $data_sub_unactive);

}
$data_current["productsUnactive"] = $data_products_unactive;
}


array_push($data_products, $data_sub);


}

$data_current["products"] = $data_products;

大家好!在这个查询中,我应该只选择主查询中尚未出现的产品。我正在检查 ID 是否与您看到的相同。例如,我使用主查询加载 4 个产品(共 15 个),在这种情况下,非事件状态应加载 11 个项目.. 但加载 14 个项目.. 因此它仅从列表中“删除”一个产品。有什么线索吗?

谢谢!

最佳答案

SELECT * FROM `product_list` WHERE ID != '" . $row_sub{'ID'} . "' ";

此查询一次检查 1 个 ID,并且始终返回其他 14 行。您需要的是像这样的“NOT IN”查询:

SELECT * FROM `product_list` WHERE ID NOT IN ("id1","id2","id3","id4");

关于mysql - SQL 不只显示一种产品,而是显示更多产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39568504/

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