Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass multiple queried results to new a query
    text
    copied!<p>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!) </p> <p><strong>My question is:</strong> 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? </p> <p><strong>Also</strong> 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.</p> <p>My <strong>MODEL</strong> code is as follows:</p> <pre><code>function check() { $this-&gt;db-&gt;select('msgto_message'); $this-&gt;db-&gt;from('msgto'); $this-&gt;db-&gt;where('msgto_display', 'y'); $this-&gt;db-&gt;where('msgto_recipient', '1'); $w = $this-&gt;db-&gt;get(); if ($w-&gt;num_rows() &gt; 0) { $rowe = $w-&gt;row_array(); $datas = $rowe['msgto_message']; } $sql = "SELECT msg_content FROM msg WHERE msg_id = ?"; $data = $this-&gt;db-&gt;query($sql, $datas) or die(mysql_error()); if ($data-&gt;num_rows() &gt; 0) { foreach($data-&gt;result_array() as $row) { $data = $row; } return $data; } } </code></pre> <p>My <strong>CONTROLLER</strong> code is as follows:</p> <pre><code>function index() { $this-&gt;load-&gt;model('data_model'); $data['rows'] = $this-&gt;data_model-&gt;check(); $this-&gt;load-&gt;view('home', $data); } </code></pre> <p><strong>Thank you anyone that helps me, I greatly appreciate it!</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload