2012-10-18 28 views
0
public function display($date) 
     { 
      $this->db->select('*');   
      $this->db->from('event'); 
       $this->db->where('start_date','$date'); 
        $res = $this->db->get()->result_array();   
       return $res; 
     } 
    } 

我在Codeigniter中使用此代碼來從我的數據庫中獲取數據。但我得到的錯誤爲「轉換日期和/或時間從字符串在SQL中轉換失敗」.anyone請幫助。codeigniter與sql

回答

0

沒有'分號$日期變量:

public function display($date) { 
$this->db->select('*'); 
$this->db->from('event'); $this->db->where('start_date',$date); 
$res = $this->db->get()->result_array(); 
return $res; 
} 
+0

消息:strtotime()[function.strtotime]:依靠系統的時區設置是不安全的。您*必須*使用date.timezone設置或date_default_timezone_set()函數。如果您使用這些方法中的任何一種,並且仍然收到此警告,則很可能是拼寫錯誤的時區標識符。我們選擇'亞洲/加爾各答'爲'5.5 /沒有DST',而不是....現在我得到這個錯誤 – user1635929

+0

刪除分號爲$ data變量在哪裏語句 – 2012-10-18 12:23:04

+0

仍然我得到錯誤 – user1635929

0
public function display($date) 
     { 
      $this->db->select('*');   
      $this->db->from('event'); 
       $this->db->where('start_date',cast($date as date)); 
        $res = $this->db->get()->result_array();   
       return $res; 
     } 
    } 

它應該是合適的日期格式鑄就$日期應該是在格式YYYY-MM-DD,否則構建的ADATE格式的像這樣發送日期

$newdate=date_create($date); 
$perfectdate=date_format($newdate,'Y-m-d');