CodeIgniter Forums
Split active record with if else statement - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Split active record with if else statement (/showthread.php?tid=44081)



Split active record with if else statement - El Forum - 08-02-2011

[eluser]Unknown[/eluser]
Hello all,

I am struggling on this. Is it possible (and how) to have an if else statement within the use of active records.

My active record:

Code:
$q = $this->db
                ->select('*')
                ->where('this_column', 'that')
                ->where('that_column', 'other')
                ->get('projects');

        if($q->num_rows > 0){
            return $q->result();
        }else{
            return false;
        }

So is it possible and how to have an if else statement like:

Code:
$q = $this->db
                ->select('*')
                ->where('this_column', 'that')
                ->where('that_column', 'other');

if($statement){
            $q ->like('another_column', '%blah%');
        }

}

$q->get('projects');

        if($q->num_rows > 0){
            return $q->result();
        }else{
            return false;
        }

I have tried this, but returns a notice error 'Message: Undefined property: CI_DB_mysql_driver::$num_rows'

Who can help me with this?

greetz,
walter


Split active record with if else statement - El Forum - 08-02-2011

[eluser]danmontgomery[/eluser]
Code:
$this->db
    ->select('*')
    ->where('this_column', 'that')
    ->where('that_column', 'other');

if($statement){
    $this->db->like('another_column', 'blah');
}

$q = $this->db->get('projects');

if($q !== FALSE && $q->num_rows() > 0){
    return $q->result();
} else {
    return FALSE;
}



Split active record with if else statement - El Forum - 08-02-2011

[eluser]Daksh Mehta[/eluser]
mis post, sorry!