2014-10-07 52 views
2
function updateVisitsStatus($today){ 
     /* 
     * 
     $this->db->select('exp_datetime, status_id'); 
     $this->db->from('visits'); 
     $this->db->where('exp_datetime <', $today); 
     $this->db->where('status_id', 0); 
     echo "<pre>"; print_r($this->db->get()->result());exit; 
     * 
     */ 

     $this->db->where('exp_datetime <', $today); 
     $this->db->where('status_id', 0); 
     $this->db->update('visits', 'status_id = -4 '); 
    } 

評論查詢使用給定條件打印兩條記錄。所以查詢應該用status_id中的新值更新兩條記錄,但實際上沒有。我無法在codeigniter中運行更新查詢

我在這個過程中遺漏了什麼?

回答

2

您必須將值作爲數組或對象傳遞給函數update。嘗試用,

// define array of values 
$data = array(
       'status_id' => -4 
      ); 
$this->db->where('exp_datetime <', $today); 
$this->db->where('status_id', 0); 
$this->db->update('visits',$data); 
+0

沒錯,就是它!謝謝你! – goseo 2014-10-07 06:50:46

+0

@ AfghanWiz..Always welcome :) – Jenz 2014-10-07 06:51:21

1

嘗試這樣

$data = array(
      'status_id' => -4 
     ); 
$this->db->where(" exp_datetime < '".$today."'"); 
$this->db->where('status_id', 0); 
$this->db->update('visits',$data);