CodeIgniter - Changing a regular query to an active record query
I was wondering if someone could show me how to change the following sql query to codeigniters active record structure?
$query = $this->db->query('SELECT * FROM '.$this->table_name.' WHERE firstname LIKE "%'.$searchterm.'%" OR lastname LIKE "%'.$searchterm.'%"');
return $query-&g开发者_如何学Ct;result();
Cheers
Try:
$this->db->like('firstname', $searchterm);
$this->db->or_like('lastname', $searchterm);
$query = $this->db->get($this->table_name);
return $query->result();
$query = $this->db->get($this->table_name)->like('firstname', $searchterm)->or_like('lastname', $searchterm);
For more information on CodeIgniter's database library, see this documentation.
精彩评论