Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter where and like sql query statement

I am trying to do this sql query on codeigniter

SELECT* FROM person WHERE type = 'staff' AND description LIKE 'university%'

I am not sure if it is correct...

$this->db->get_where('person' , array('type'=>'staff'))
         ->like('description','university%')
         ->result_array();

does anyone have an idea about my case? thanks in advance ...

like image 315
gadss Avatar asked Apr 12 '14 07:04

gadss


1 Answers

Using Active Record you can do so

$query = $this->db->select('*')
             ->from('person')
             ->where('type','staff')
             ->like('description','university','after')
             ->get();

$result = $query->result_array();

Make sure you pass after as a third parameter in like() function so active record will add the wild card i.e % after university so it will look like LIKE 'university%'

like image 117
M Khalid Junaid Avatar answered Oct 10 '22 02:10

M Khalid Junaid