0

I'm experiencing a serious problem when I'm trying to make my CodeIgniter model comunicate with database properly.

In the answer I found in this topic I read that I shouldn't make queries like this:

            $query2 = $this->db->query("SELECT patient_id FROM visits
                          WHERE date LIKE DATE_FORMAT('$row->date', '%Y-%m-%d') GROUP BY date");    

but like that:

$this->db->select('patient_id');
$this->db->from('visits');
$this->db->like('date', "DATE_FORMAT($row->date, '%Y-%m-%d')"); 

Although, still can't figure out how to make it work. I'm also not sure if I used $this->db->like properly.

Community
  • 1
  • 1
coobek
  • 3
  • 2

1 Answers1

1

you just need to call:

$query = $this->db->get();

to get the results. Also, you dont need to $this->db each time, so your query could look like this:

$this->db
    ->select('patient_id')
    ->from('visits')
    ->like('date', "DATE_FORMAT($row->date, '%Y-%m-%d')", FALSE); 
 $query = $this->db->get();
SwiftD
  • 5,769
  • 6
  • 43
  • 67
  • You need to pass FALSE as 3rd argument in the like() call, or the whole query expression will be escaped and compared as is – Damien Pirsy Dec 22 '12 at 12:25
  • Thank you so much for the answer! :) That's actually nice and clean solution. And definitely easier to read. Sometimes you just need another brain ;) Thanks again! – coobek Dec 22 '12 at 12:40