Php 从日期选择记录并忽略不工作的时间部分
我有一个奇怪的情况。我使用内置的calendar类使用codeigniter创建了一个日历。任何事情都可以抓取事件并将它们放在日历上,所以我知道选择日期是有效的。。。但现在我试图选择某个特定日期的记录,例如2014-03-28,但无论我使用什么查询,它都不会从该日期提取记录。我有一张桌子,开始日期是我试图通过的日期,它被设置为dateTime。任何关于我做错了什么的想法,以下是我尝试过的(输入函数的起始日期等于Y-m-d,如2014-03-28): 还尝试了最明显的方法:Php 从日期选择记录并忽略不工作的时间部分,php,codeigniter,datetime,activerecord,time,Php,Codeigniter,Datetime,Activerecord,Time,我有一个奇怪的情况。我使用内置的calendar类使用codeigniter创建了一个日历。任何事情都可以抓取事件并将它们放在日历上,所以我知道选择日期是有效的。。。但现在我试图选择某个特定日期的记录,例如2014-03-28,但无论我使用什么查询,它都不会从该日期提取记录。我有一张桌子,开始日期是我试图通过的日期,它被设置为dateTime。任何关于我做错了什么的想法,以下是我尝试过的(输入函数的起始日期等于Y-m-d,如2014-03-28): 还尝试了最明显的方法: function ge
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;
}
函数获取列表事件($start\u date){
$start_date=日期('Y-m-d H:i:s',标准时间('start_date.'00:00:00');
$start_time=date('Y-m-d H:i:s',strottime('start_date.'23:59:59');
$this->db->where('active',1);
$this->db->where('start\u date>=',$start\u date);
$this->db->where('start_date我建议您使用
// ... Code above ...
$query = $this->db->get('events');
echo $this->db->last_query();
die();
然后获取您针对DDBB抛出的查询。这样,您就可以通过MySQL客户端抛出该查询,并查看您是否真的通过CI使用的查询获得行
事实上,您编写的第一个代码块看起来不错,其他代码块有一个$this->db->where('active',1)
第一个没有,所以,再次检查查询,XD。检查我的答案,我想你的查询可能是错误的我正在提取的记录都是活动的==1。所以删除where-active不会影响查询。还有其他想法吗?顺便说一句,我尝试了所有查询删除活动部分,仍然不起作用。你能发布查询吗您使用上一个查询()得到了什么(检查答案)?
// ... Code above ...
$query = $this->db->get('events');
echo $this->db->last_query();
die();