CodeIgniter Forums
CI3, active record contain $offset,$limit - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: CI3, active record contain $offset,$limit (/thread-76884.html)



CI3, active record contain $offset,$limit - kelapamuda - 06-29-2020

Hello, i already have   model that is this 

PHP Code:
$q $this->db->query("select * from employee where coloumnA like '%$keyword%' OR columnB like  '%$keyword%' LIMIT $offset,$limit");
return 
$q

I want to change it into query builder sentences,how to do it? I tried several times, but it gave errors.
Thanks


RE: CI3, active record contain $offset,$limit - neuron - 06-29-2020

`$this->db->select('*')
->from('employee e')
->group_start() //this is not necessary, just added in case you will need in future. it will wrap query like statements in parentheses. there is also or_group_start()
->or_like('e.columnA', $keyword)
->or_like('e.columnB', $keyword)
->group_end()
->limit($limit, $offset);`

//added alias "e", but is not necessary

//to get results
`return $this->db->result_array(); `

//to see the generated SQL code:
`$sql = $this->db->get_compiled_select();`

It is simple query, you can figure about easily if you look in CI v3.x documentation
https://codeigniter.com/userguide3/database/query_builder.html