title: Codeigniter - loop through post information passing value to model query and outputting result
body: <p>I have my form data being passed to the new controller/view.</p>
  
  <p>I want to loop through the $_POST array, pass the value to the controller/model, query the database and return the result to the view to be displayed.</p>
  
  <p>So I have the below code in my View:</p>
  
  <pre><code>foreach($_POST as $key =&gt; $value) //$key is productcode eg '4560'
      {
         $this-&gt;sales_model-&gt;get_productdetails($this-&gt;input-&gt;post('$key'))
         echo "Price: ".$price."&lt;br&gt;";
         echo "Pieces: ".$pieces."&lt;br&gt;";
         echo "Cubic Meters: ".$cubicmeters."&lt;hr&gt;";
  
      }
  </code></pre>
  
  <p>This is my model:</p>
  
  <pre><code>function get_productdetails($productcode)
  {
      $this-&gt;db-&gt;select('price,pieces,cubicmeters');
      $this-&gt;db-&gt;from('ProductList');
      $this-&gt;db-&gt;where('productcode',$productcode);
      $q = $this-&gt;db-&gt;get();
      if($q-&gt;num_rows() &gt; 0) 
      {
          return $q-&gt;row_array(); 
      }
  }
  </code></pre>
  
  <p>Controller:
  function new_auto_spread_details() 
    {
       $this->load->view('sales/new_autospread_order_lines');
    }</p>
  
  <p>This does not work correctly. How do I output/display the query results on the view? can this be done and if not how is this achieved with best practice?</p>
  
  <p>Thanks as always,</p>