0

I have the following condition in ExpressionEngine (which is using CodeIgniter framework):

if ($group_id !== '')
    {
        $this->db->where("members.group_id", $group_id);
    }

I´d like to add an extra condition to that where (an AND), how can I do this? Do I add a new $this->db->where('my_field', $my_value)? Or how?

0

4 Answers 4

2

You guessed it.

if ($group_id !== '')
{
    $this->db->where("members.group_id", $group_id);
    $this->db->where('my_field', $my_value);
}

Check Codeigniter documentation http://codeigniter.com/user_guide/database/active_record.html It's good.

Sign up to request clarification or add additional context in comments.

Comments

0
// if (is_numeric($group_id) && $group_id > 0)
if ($group_id)
{
    $this->db->where("members.group_id", $group_id);
    $this->db->where('my_field', $my_value);
    // $this->db->where('my_field >=', $my_value);
    // $this->db->where('my_field <', $my_value);
}

Comments

0

What i do is write out the query such as:

$data = array('name' => $_POST['name'], 'lname' => $_POST['lname']);
$sql = "select table where name = ? and lname = ?";
$this->db->query($sql, $data);

the reason why i prefer to write it out is because once you end up writing very complex queries with many table joins it becomes really difficult to read active record queries.

1 Comment

It is not recommended in CodeIgniter projects to use $_POST or $_GET. CI has its own helper methods to access submission data.
0

Yah.....u can try this:

if ($group_id !== '')
{
    $this->db->where("members.group_id", $group_id);
    $this->db->where('my_field', $my_value);
}

u can also use:

$this->db->or_where('my_field',$my_value);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.