CodeIgniter where and how sql query request

I am trying to execute this sql query on codeigniter

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

I'm not sure if this 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...

+4
source share
3 answers

Using Active Record , you can do it

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

$result = $query->result_array();

Make sure that you pass afteras the third parameter in the function like(), so an active record will add a wild card ie %after universityso that it looks likeLIKE 'university%'

+6
source

I have never used a chain (although I know this is possible), but breaking your question should be easy;

$this->db->from('person');
$this->db->where('type','staff');
$this->db->where('description', 'university%');
$query = $this->db->get();
$result = $query->result_array();
return $result;
0

docs , API . , :

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

$query  = $this->db->get();
$result = $query->result_array(); 
0

Source: https://habr.com/ru/post/1536216/


All Articles