CodeIgniter Forums
Query question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Query question (/thread-29967.html)



Query question - El Forum - 04-27-2010

[eluser]RobertB.[/eluser]
Hello again guys;

Hopefully someone understand what I'm trying to do.

Trying to get results from the second table based on the results of the first query but this returns only the results from the first table that I don't want. I want to get the results from the second table. Can someone give me a little push

MODEL
Code:
function Function($id)
    {
        $this->db->select('col1, col2');
        $this->db->from('table1');
        $this->db->where('id', $id);

        $query = $this->db->get();
        return $query->row();
            
        $col1 = $query->row('col1');
        $col2 = $query->row('col2');    
        
        $cols = $col1 + $col2;
        
        $this->db->select('col3');
        $this->db->from('table2');
        $this->db->where('col3', $cols);
        
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
    }

CONTROLLER
Code:
function getResults()
    {
       $id = 1;

       $data['result'] = $this->model->function($id);
       print_r($data['result']);
    }

Thanks.


Query question - El Forum - 04-27-2010

[eluser]RobertB.[/eluser]
SOLVED, There is nothing wrong with this query I was just executing it wrong.
Sorry.