Welcome Guest, Not a member yet? Register   Sign In
How to reference the value of a result in a second query
#2

(This post was last modified: 12-12-2015, 04:15 PM by solidcodes.)

You can use one to many relationship, so the table must look like this below,

Code:
Organization
-------------------------------------
org_id | person_id | more columsn here ....      
-------------------------------------
        
People
-------------------------------------
person_id | more columsn here ....      
-------------------------------------


The Query
Code:
function get_record_by_id($person_id)
    {
            $q = $this->db->select('org_id, person_id, organization')
                             ->from('organization')
                             ->where('person_id', $person_id)
                             ->limit(1)
                             ->get();

            if($q->num_rows() > 0) {
                    foreach ($q->result() as $row) {
                            //$data[] = $row;
                            $data = $row->organization;
                    }

                    return $data;
            }
    }


Not tested buy try...
No SEO spam
Reply


Messages In This Thread
RE: How to reference the value of a result in a second query - by solidcodes - 12-12-2015, 04:04 PM



Theme © iAndrew 2016 - Forum software by © MyBB