Reputation: 303
I am stuck with this query , please tell me how to convert this query into codeigniter active record method
select * from view_log where user_id=XXXX and date(time) = curdate();
where time is a time stamp , so I want to extract date out of it and compare it with today's date. I have tried to use set
but its not working, even passing it as a string
is not working.
Upvotes: 0
Views: 3533
Reputation: 87
Or simplely, you can use this code $query = $this->db->query($sql);
But before using any mysql query in controller, you should try to run it in phpmyadmin. I think you will know extractly your query is right or wrong ...
Upvotes: 0
Reputation: 36531
try this
$this->db->select('*');
$this->db->from('view_log');
$this->db->where('user_id=XXXX and date(time) = curdate()');
$result=$this->db->get();
or the simplest way
$this->db->select('*');
$this->db->from('view_log');
$this->db->where('user_id','XXX');
$this->db->where('DATE(time)', 'CURDATE()', FALSE);
$result=$this->db->get();
Upvotes: 4
Reputation: 9054
I think date is a field in our table
if date is a field in you table try this way
$this->db->select('*');
$this->db->from('view_log');
$this->db->where('user_id','XXX');
$this->db->where('date', 'CURDATE()', FALSE);
$result=$this->db->get();
Upvotes: 2