如何用0000-00-00清空日期字段?

时间:2015-12-22 14:50:51

标签: php mysql

$array = Array(
     [FetchedData_I] => 1
     [EM_Account_V] => Test 2
     [EM_Date_D] => 2015-11-20
     [EM_Time_T] => 00:00:00
     [Channel_V] => 
     [OD_Online_Listing_ID_V] => 
     [OD_Item_Name_V] => Item Namesdsd
     [OD_Color_V] => 
     [OD_Condition_V] => 
     [OD_Qty_V] => 1
     [OD_Order_Date_D] => 0000-00-00
     [OD_Order_Time_T] => 00:00:00
     [OD_Ship_By_Date_D] => 0000-00-00
     [Comments_Internal_B] => 
 );

以上是查询返回的mysql数据,方案是忽略空数据并处理其他数据。

我目前正在使用:

foreach($array as $value) {
   if($value!='') {
      //Process the other
   }
}

在上述情况下,如何检查时间和日期的空数据,例如EM_Time_TOD_Order_Date_D等,看看它们是否为空?

1 个答案:

答案 0 :(得分:6)

不要尝试在PHP中处理public function queryWhile($query){ $query = htmlspecialchars($query); $this->result = mysqli_query($this->db, $query); if(!$this->result){ echo "No response"; $this->closeDB(); }else{ while ($row = mysqli_fetch_array($this->result)){ $this->resultArray[] = $row; } } } return $this->queryWhile("SELECT articles.article_id, articles.PreviewText, articles.date,articles.Title, articles.previewText, image.thumbnail, articleAuthTable.nickname AS authorNickname, imageAuthTable.nickname AS imageNickname FROM articles LEFT JOIN image ON articles.previewImage = image.image_id LEFT JOIN authors AS articleAuthTable ON articles.author = articleAuthTable.author_id LEFT JOIN authors AS imageAuthTable ON image.author = imageAuthTable.author_id WHERE articles.categories = '".$this->category."' ORDER BY date DESC;"); 。相反,请修复表格中的问题。

在phpMyAdmin中,编辑表格的结构并勾选每个日期字段的0000-00-00框。这意味着如果在插入时未设置字段,则会改为NULL

然后,在phpMyAdmin中运行以下SQL,但根据需要更改NULLtable_name

field_name

要回答您的PHP UPDATE table_name SET field_name = NULL WHERE field_name = '0000-00-00'; 问题,您的代码应如下所示:

foreach
相关问题