Welcome Guest, Not a member yet? Register   Sign In
Split active record with if else statement
#1

[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
#2

[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;
}
#3

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




Theme © iAndrew 2016 - Forum software by © MyBB