0
我有一個奇怪的情況。我已經使用內置的日曆類創建了帶codeigniter的日曆。一切工作,只要抓住事件,並把它們放在日曆上,所以我知道選擇日期的作品...但現在我試圖選擇記錄在特定日期,如2014-03-28,但無論我用什麼查詢並不是從那天開始記錄。我有一個表,start_date是我試圖拉動的日期,其設置爲dateTime。任何想法,我做錯了什麼,這裏是我試了一下(開始被饋送到功能等於YMD像2014年3月28日):從日期選擇記錄並忽略時間部分不工作
function get_list_events($start_date) {
$start_date_start = date('Y-m-d', strtotime($start_date.' 00:00:00'));
$start_date_end = date('Y-m-d', strtotime($start_date.' 23:59:59'));
$this->db->where("start_date BETWEEN '$start_date_start%' AND '$start_date_end%'", NULL, FALSE);
$query = $this->db->get('events');
$data = array();
foreach ($query->result() as $row) {
$data[] = array(
'id' => $row->id,
'title' => $row->title,
'description' => $row->description,
'cost' => $row->cost,
'image' => $row->image,
'start_date' => $row->start_date,
'end_date' => $row->end_date,
'venue' => $row->venue,
'venue_address' => $row->venue_address,
'venue_city' => $row->venue_city,
'venue_state' => $row->venue_state,
'venue_zipcode' => $row->venue_zipcode,
'contact_name' => $row->contact_name,
'contact_email' => $row->contact_email,
'contact_phone' => $row->contact_phone,
'contact_website' => $row->contact_website,
'create_date' => $row->create_date,
'active' => $row->active,
);
}
return $data;
}
也嘗試了最明顯的方法:
function get_list_events($start_date) {
$start_date = date('Y-m-d', strtotime($start_date));
$this->db->where('active', 1);
$this->db->where('start_date', $start_date);
$this->db->order_by('start_date', 'desc');
$query = $this->db->get('events');
$data = array();
foreach ($query->result() as $row) {
$data[] = array(
'id' => $row->id,
'title' => $row->title,
'description' => $row->description,
'cost' => $row->cost,
'image' => $row->image,
'start_date' => $row->start_date,
'end_date' => $row->end_date,
'venue' => $row->venue,
'venue_address' => $row->venue_address,
'venue_city' => $row->venue_city,
'venue_state' => $row->venue_state,
'venue_zipcode' => $row->venue_zipcode,
'contact_name' => $row->contact_name,
'contact_email' => $row->contact_email,
'contact_phone' => $row->contact_phone,
'contact_website' => $row->contact_website,
'create_date' => $row->create_date,
'active' => $row->active,
);
}
return $data;
}
最後,我想這:
function get_list_events($start_date) {
$start_date = date('Y-m-d H:i:s', strtotime($start_date.' 00:00:00'));
$start_time = date('Y-m-d H:i:s', strtotime($start_date.' 23:59:59'));
$this->db->where('active', 1);
$this->db->where('start_date >=', $start_date);
$this->db->where('start_date <=', $start_time);
$this->db->order_by('start_date', 'desc');
$query = $this->db->get('events');
$data = array();
foreach ($query->result() as $row) {
$data[] = array(
'id' => $row->id,
'title' => $row->title,
'description' => $row->description,
'cost' => $row->cost,
'image' => $row->image,
'start_date' => $row->start_date,
'end_date' => $row->end_date,
'venue' => $row->venue,
'venue_address' => $row->venue_address,
'venue_city' => $row->venue_city,
'venue_state' => $row->venue_state,
'venue_zipcode' => $row->venue_zipcode,
'contact_name' => $row->contact_name,
'contact_email' => $row->contact_email,
'contact_phone' => $row->contact_phone,
'contact_website' => $row->contact_website,
'create_date' => $row->create_date,
'active' => $row->active,
);
}
return $data;
}
任何幫助表示讚賞。
檢查我的答案,我認爲你的查詢可能是錯誤的 – Chococroc
我拉的記錄都有活動== 1.因此,刪除活動的地方不會影響查詢任何方式。任何其他想法? –
順便說一句,我試過所有的查詢刪除活動部分,仍然無法正常工作。 –