Welcome Guest, Not a member yet? Register   Sign In
or_where problem with active record

This is probably simple but I don't see it.
$pages = explode(",",$pages_string);
$this->db->select('name, text,page_number');
$q = $this->db->get('articles');

This will write ors for all 3 conditions but as you guessed i want ors for the page numbers and AND for the article_id.
Can I do this with active record or do I need to just use $this->db->query()?

You'd have to manually write that in a single where.

Something like:
$this->db->where('article_id = ' . $id . ' AND (page_number = ' . $pages[0] . ' OR page_number = ' . $pages[1] . ')');

The upcoming CI3 will have abilities to do compound AND/OR/etc.

Thanks. Was just checking. Looking forward to CI3!!

Actually, you could use a WHERE IN for your query, since it has to be one page number or the other.

$this->db->where_in('page_number', array($pages[0], $pages[1]));

Perfect and as $pages is an array:

Cool, didn't know if you had more/unrelated data in your $pages array.

didn't know CI3 will be coming very soon. looking forward to it.

Theme © iAndrew 2016 - Forum software by © MyBB