更新不等于今天日期Mysql的所有记录

问题描述 投票:-1回答:1

我在mysql名称为“ userInfo”中具有下表,并且我想更新记录,其中date!=今天的日期

这是我的表“ userInfo”

Id          shopId          notificationStatusforShopOpen           updatedTimeForShopOpen
1           10              1                                       2020-06-06 18:01:02
2           11              1                                       2020-06-04 18:01:02
3           12              1                                       2020-06-07 18:01:02

我尝试使用以下代码,但是无法正常工作,这意味着我不对任何记录进行更新?

UPDATE `userInfo` SET `notificationStatusforShopOpen` = NULL 
WHERE DATE(updatedTimeForShopOpen) != '2020-06-07' 
OR `updatedTimeForShopOpen` IS NULL 
php mysql
1个回答
-1
投票
  1. 请确保notificationStatusforShopOpen列可以接受NULL值。
  2. 您必须在上述栏中指定时间。因此应该考虑。

    $query = SELECT id,updatedTimeForShopOpen FROM table_name WHERE updatedTimeForShopOpen != null;
    
    $array = $query->select_array();
    
    $Tdate=date_create(date('Y-m-d'));
    
    foreach ($array as $key) {
    
     $Cdate = date_create($key['updatedTimeForShopOpen']);
    
     $Cdate = date_format($Cdate,'Y-m-d');
    
     if($Cdate == $Tdate) {
    
      UPDATE `userInfo` SET `notificationStatusforShopOpen` = NULL where id = $key('id');
    
        }
    
     }
    
© www.soinside.com 2019 - 2024. All rights reserved.