0

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.

3 Answers 3

4

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();
Sign up to request clarification or add additional context in comments.

2 Comments

are you getting any error ?? if yes then please let me know the error that you are getting
$this->db->where('user_id',$user_id); $this->db->where("DATE(time)",'CURDATE()',false); This worked for me ! Thank bipen for your answer
2

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();

1 Comment

$this->db->where('user_id',$user_id); $this->db->where("DATE(time)",'CURDATE()',false); This worked for me ! Thank mehdi for your answer.
0

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 ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.