My mistakes

Archive for February 2009

when someone trying to or two conditions using active record database library in codeigniter

Eg:

$this->db->from('posts');

$this->db->where('id', $id);

$this->db->like('title', $title);

$this->db->like('body', $body);
$this->db->or_like('author', $author);

You can do it like this

$this->db->from('posts');

$this->db->where('id', $id);
$this->db->where('(`title` LIKE \'%'.$title.'%\' OR `body` LIKE \'%'.$body.'%\' OR `author` LIKE \'%'.$author.'%\')', NULL, FALSE);

// Query:

// SELECT * FROM (`posts`) WHERE (`title` LIKE '%ach%' OR `text` LIKE '%ach%' OR `author` LIKE '%ach%') AND `id` = '12'