开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜