Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to list only active records with select from?

I need to make a query to return only active records which in this case are imo_status == 1

What is the best way to make this query? I’m using CI3

Below is the source code.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

// LISTA OS AGENCIAMENTOS NO BANCO DE DADOS
public function getProperties()
{   

    $this->db->select('*');
    $this->db->from('ci_properties');
    $this->db->where('imo_status' == 1);
        return $this->db->get("ci_properties")->result_array();

    /*$query = $this->db->get("ci_properties");
    return $query->result_array();*/
}

>Solution :

You build the query then don’t use it:

return $this->db->get("ci_properties")->result_array();

This wipes out the query builder and basically does a ‘get all’ from ‘ci_properties’. To use you’re query:

$query = $this->db->get();        
return $query->result();

This is because you have already specified the table in the ‘from’ part, get(‘table name’), will get all.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading