Welcome Guest, Not a member yet? Register   Sign In
one query's multiple results into new query? :S
#1

[eluser]Maiden13[/eluser]
Hi there,

I have succeeded in querying one table to get information that is needed to query another table (If you can see a better way I would be grateful!)
My question is: How can I have multiple values come back from the first query and have my second query come back with multiple results.
As you can see I am inserting the returned result from query one into query two "msg_id = ?"(I use $datas to fill the '?') but if my results from query one have multiple values then how will this work? Also how can I make it get multiple results from query one? at the moment if there are multiple values in mysql it only grabs the first one it reads.

My MODEL code is as follows:
Code:
function check() {
        $this->db->select('msgto_message');
        $this->db->from('msgto');
        $this->db->where('msgto_display', 'y');
        $this->db->where('msgto_recipient', '1');
        
        $w = $this->db->get();
        
        if ($w->num_rows() > 0) {
               $rowe = $w->row_array();

               $datas = $rowe['msgto_message'];
        }

        $sql = "SELECT msg_content FROM msg WHERE msg_id = ?";

    $data = $this->db->query($sql, $datas) or die(mysql_error());
        
    if ($data->num_rows() > 0) {
        foreach($data->result_array() as $row) {
            $data = $row;
            }
            
            return $data;
        }
        
    }

My CONTROLLER code is as follows:
Code:
function index() {
        $this->load->model('data_model');
        $data['rows'] = $this->data_model->check();
        
        $this->load->view('home', $data);
    }

Thank you anyone that helps me, I greatly appreciate it!


Messages In This Thread
one query's multiple results into new query? :S - by El Forum - 12-07-2010, 09:55 PM
one query's multiple results into new query? :S - by El Forum - 12-08-2010, 02:57 AM
one query's multiple results into new query? :S - by El Forum - 12-08-2010, 03:15 AM
one query's multiple results into new query? :S - by El Forum - 12-08-2010, 03:24 AM
one query's multiple results into new query? :S - by El Forum - 12-08-2010, 11:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB