我使用phpMyAdmin 3.5.2,笨2.1爲我的網站,MySQL的日期時間列操作
我的問題是當我嘗試加載準確的日子增加職位,或當我只想顯示日期/時間那篇文章。
表結構
CREATE TABLE IF NOT EXISTS `posts` (
`post_id` int(11) NOT NULL AUTO_INCREMENT,
`patient_id` int(11) NOT NULL,
`worker_id` int(11) NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`stats` varchar(20) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`post_id`),
KEY `worker_id` (`worker_id`,`patient_id`),
KEY `patient_id` (`patient_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2 ;
我的問題是操縱此 '時間' 列,因爲我需要顯示例如
1)表中顯示當今交(是使用
Select * from posts where date(`time`) = date(NOW())
2)表顯示今天的帖子,但時間列只返回(TIME) 和多數民衆贊成我的主要問題,因爲如果我這樣做
select time from posts
返回日期和時間,我只希望從列返回的時間,但仍然能夠使用
where date('time') =date(now()) condition !.
那麼有沒有更好的方法來做到這一點?即使我可以在PHP中做到這一點仍然很好!
或者如果我把時間和日期分成2個不同的列,那麼它會更好嗎?問題的
--------第二部分是用於笨----------
模型
$this->db->select('patients.name,workers.dr_name,time(posts.time),posts.stats');
$this->db->from('posts');
$this->db->join('workers','posts.worker_id=workers.worker_id','left');
$this->db->join('patients','posts.patient_id=patients.patient_id','left');
$this->db->where('date(`time`) = date(NOW())');
return $this->db->get();
控制器
$this->load->model('Posts_model');
$q=$this->Visits_model->allvisits;
$this->load->library('table');
$this->load->view('welcome_message');
$qq=$q->result_array();
$qq=array('patient','Doctor','Time','Stats');
$this->table->set_heading($qq);
$this->table->set_caption('Todays Posts');
echo $this->table->generate($q);
如何刪除模型中的條件(where date = Now)並使用php對此進行排序?我必須循環結果嗎?還是有更乾淨的方法來做到這一點? 感謝
感謝eggyal我現在可以查詢得到的只有時間:) – Zalaboza