Welcome Guest, Not a member yet? Register   Sign In
Active Record select question
#1

[eluser]Eric Barnes[/eluser]
Hi,

I have this query:
Code:
SELECT * FROM kb_articles WHERE a_display = 'Y' AND a_id IN ( 1,2 )

I am trying to use something similar with active record and it appears this isn't possible because it always comes out as:

Code:
SELECT * FROM kb_articles WHERE a_display = 'Y' AND a_id IN '1,2'

My ci code looks like this:
Code:
foreach ($query->result() as $row)
{
    $aID.=$row->article_id.',';
}
$aID = rtrim($aID, ', ');
$this->db->from('articles');
$this->db->where('a_display', 'Y');
$this->db->where('a_id IN', $aID);

Does any one have any advice on a work around or maybe an easier way to set this up?
#2

[eluser]Eric Barnes[/eluser]
Well I got it working. Smile I had to go the join route.

Code:
$this->db->select('*');
            $this->db->from('articles');
            $this->db->join('article2cat', 'articles.a_id = article2cat.article_id', 'left');
            $this->db->where('category_id', $id);
            $this->db->where('a_display', 'Y');
            $query = $this->db->get();
            echo $this->db->last_query();
            return $query;
#3

[eluser]alexsancho[/eluser]
You can do this too

Code:
foreach ($query->result() as $row)
{
    $aID.=$row->article_id.',';
}
$aID = rtrim($aID, ', ');
$this->db->from('articles');
$this->db->where('a_display', 'Y');
$this->db->where('a_id IN($aID)');
#4

[eluser]Eric Barnes[/eluser]
Very cool I wasn't aware of that. Wink

Would have to worry about other database system using it this way though?




Theme © iAndrew 2016 - Forum software by © MyBB