gpt4 book ai didi

php - 根据select查询结果更新数据库记录

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

您好,如果日期列包含今天的日期,我想更新价格列。以下是我的代码,但它只更新一条记录,即使有两条相同日期的记录。

代码

<?php   
require('db.php');
$tdate=date('Y-m-d');
$query = 'SELECT * FROM marketplace_product WHERE splprice_from IS NOT NULL AND splprice_to IS NOT NULL';
$result = mysqli_query($con, $query) or die(mysqli_error($con));
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{

if($row['splprice_from']==$tdate)
{
print_r($row);
$ent=$row['entity_id'];
$updatePrice="UPDATE marketplace_product SET today_price=splprice WHERE entity_id=$ent";
$result = mysqli_query($con, $updatePrice) or die(mysqli_error($con));
if($result)
echo "Price updated for id".$row['entity_id'];
else
echo "Price not updated for id".$row['entity_id'];
}
}
}

?>

打印结果

    Array ( [entity_id] => 2 [mageproduct_id] => 531 [adminassign] => 0 [seller_id] => 14 [store_id] => 0 [status] => 2 [seller_product_code] => [seller_price] => 5000.00 [splprice] => 4000.00 [splprice_from] => 2017-04-22 [splprice_to] => 2017-04-28 [today_price] => 0.00 [seller_qty] => 0 [return_qty] => [stock_per_day] => [confirmed_qty] => [pending_qty] => [sold_qty] => [canceled_qty] => [sell_limit] => 4 [discount_price] => [seller_tax] => [vat] => [cst] => [gst] => [octroi] => [created_at] => 2017-02-27 17:12:17 [updated_at] => 2017-02-27 17:12:17 ) 
Array ( [entity_id] => 3 [mageproduct_id] => 532 [adminassign] => 0 [seller_id] => 13 [store_id] => 0 [status] => 2 [seller_product_code] => [seller_price] => 5000.00 [splprice] => 4000.00 [splprice_from] => 2017-04-22 [splprice_to] => 2017-04-28 [today_price] => 0.00 [seller_qty] => 0 [return_qty] => [stock_per_day] => [confirmed_qty] => [pending_qty] => [sold_qty] => [canceled_qty] => [sell_limit] => 6 [discount_price] => [seller_tax] => [vat] => [cst] => [gst] => [octroi] => [created_at] => 2017-02-28 09:47:38 [updated_at] => 2017-02-28 09:47:38 )

以上更新查询更新的是 entity_id=2 的价格,而不是 entity_id=3 的价格。任何帮助表示赞赏。

最佳答案

亲爱的,您使用相同的对象“$result”进行选择和更新查询,请更新名称“$resultUpdate”进行更新查询。

关于php - 根据select查询结果更新数据库记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43555567/

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