开发者

CodeIgniter - Changing a regular query to an active record query

开发者 https://www.devze.com 2023-01-30 08:24 出处:网络
I was wondering if someone could show me how to change the following sql query to codeigniters active record structure?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消