title: Codeigniter model foreach pass array to controller -> to view
body: <p>Here is my model - I want to assign the rows and echo out on the view page e.g <code>&lt;?php echo $product?&gt;</code>
      
  
  <pre><code>class Model_products extends CI_Model {
  
      function printer()
      {
  
      $id = $this-&gt;uri-&gt;segment(3, 0);
  
          $q = $this-&gt;db-&gt;get_where('printer', array('id' =&gt; $id));
  
          if ($q-&gt;num_rows == 1)
          { 
              foreach ($q-&gt;result() as $row)
              {
  
                  echo $row-&gt;name; # THIS WORKS
                  $data['product'] = $row-&gt;name;  # THIS DOES NOT WORK
                  $data['desc'] = $row-&gt;description;
                  $data['size'] = $row-&gt;size;
                  $data['options'] = $row-&gt;options;
                  $data['more'] = $row-&gt;more_info;
              }
          }
  
  
      }
  }
  </code></pre>
  
  <p>Here's my controller</p>
  
  <pre><code>public function products()
  {
  
      $this-&gt;load-&gt;model('Model_products');
  
      $this-&gt;Model_products-&gt;printer();
  
      $this-&gt;load-&gt;view('products', $data);
  
      $this-&gt;load-&gt;view('pricing');
  }
  </code></pre>
  
  <p>My view is</p>
  
  <pre><code>&lt;h1&gt;
  &lt;?php echo $product; ?&gt;
  &lt;/h1&gt;
  
  &lt;p&gt;
  &lt;?php echo $desc; ?&gt;
  &lt;/p&gt;
  
  
  &lt;h3&gt;
  Size
  &lt;/h3&gt;
  &lt;p&gt;
  &lt;?php echo $size; ?&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p><strong>How do I properly pass my model array to my controller so that I can echo out on my view?</strong></p>