0

I'm trying to get some data from my database with active records,and I'm having the following problem. I wanna learn how to do it with active records since after this code i have a ton of joins and other stuff. Otherwise I would write a normal query.

        $this->db->where("sa.country", $country);


         // I NEED TO OPEN BRACKETS HERE SO THAT I CAN GET THE LANGUAGES IF THERE IS DATA IN ONE OF THE ARRAYS


        if (isset($lid[0]))$this->db->where("sa.lang", $lid[0]);
        if (isset($lid[1]))$this->db->or_where("sa.lang", $lid[1]);
        if (isset($lid[2]))$this->db->or_where("sa.lang", $lid[2]);
        if (isset($lid[3]))$this->db->or_where("sa.lang", $lid[3]);
        if (isset($lid[4]))$this->db->or_where("sa.lang", $lid[4]);


        //AND CLOSE THEM HERE

My goal is to get a specific country from db, with the corresponding languages that are in the arrays.

4

3 回答 3

0

这有帮助吗?

$this->db->where("sa.country", $country);

// loop through *set* languages
foreach($lid as $item)
{
    $this->db->where('sa.lang', $item);
}

// will return a query object
return $this->db->get('my_table');
于 2012-10-12T01:01:21.477 回答
0

我认为你应该使用WHERE...IN...!请参阅有关“在哪里”的帮助。

使用 ActiveRecord:

$this->db->where_in("sa.lang",$lid);
于 2012-10-12T06:15:54.100 回答
0

这是我为对解决方案感兴趣的任何人解决问题的方法。

$this->db->where("(`sa`.`lang` = '$lid[0]' OR `sa`.`lang` = '$lid[1]' OR `sa`.`lang` = '$lid[2]' OR `sa`.`lang` = '$lid[3]' OR `sa`.`lang` = '$lid[4]')");
于 2012-10-12T04:21:28.433 回答