CodeIgniter Forums
Where something and something SQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Where something and something SQL (/showthread.php?tid=48910)



Where something and something SQL - El Forum - 02-01-2012

[eluser]kolxoznik1[/eluser]
I have read user_guide and do not found WHERE something AND something.

So I need to check WHERE a = 3 and a = 5

so as I understand

Quote: $this->db->where('user_id', $user_id);
$this->db->where('follow_id', $follow_id);


two WHERE mean AND ?

Code:
function add_follow($user_id, $follow_id)
    {
        $this->db->select('user_id');
        $this->db->where('user_id', $user_id);
        $this->db->where('follow_id', $follow_id);
        $query = $this->db->get('user_follow');
        if ($query->num_rows() == 0) {
            $this->db->set('user_id', $user_id);
            $this->db->set('follow_id', $follow_id);
            $this->db->insert('user_follow');        
        }
        return FALSE;
    }

is it correct?


Where something and something SQL - El Forum - 02-01-2012

[eluser]Patrick Spence[/eluser]
[quote author="kolxoznik1" date="1328148220"]I have read user_guide and do not found WHERE something AND something.



is it correct? [/quote]

That's how I use it.



Where something and something SQL - El Forum - 02-01-2012

[eluser]CroNiX[/eluser]
Yep, that's exactly what the example in the user guide shows for where() in active record.
Quote:$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status);

// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'



Where something and something SQL - El Forum - 02-02-2012

[eluser]vbsaltydog[/eluser]
Alternatively using method chaining:

Code:
$this->db
->where(‘name’, $name)
->where(‘title’, $title)
->where(‘status’, $status);