title: Codeigniter - How data list with multiple tables
body: <p>i have two tables of database
  1st table is: Products
  *id
  *brand
  *model</p>
  
  <p>2nd table is:  Sales
  *id
  *pid
  *date</p>
  
  <p>i want to create list with getting data form both tables.</p>
  
  <p><em><strong>here is my Model:</em></strong></p>
  
  <pre><code>class Sales_model extends CI_Model {
      function getAll() {
  
  
          $q = $this-&gt;db-&gt;get('sales');
          foreach ($q-&gt;result() as $row) {    
              $data[] = $row;
  
              $q2 = $this-&gt;db-&gt;get_where('products', array('id' =&gt; $row-&gt;pid));
  
              foreach ($q2-&gt;result() as $row2) {
                  $data[] = $row2;
              }
  
          }
          return $data;
  }
  </code></pre>
  
  <p>-------- and here is controller code ------------</p>
  
  <pre><code>class Sales extends CI_Controller {
  
      function __construct()
      {
          parent::__construct();
      }
  
      public function index()
      {
          $this-&gt;load-&gt;model('sales_model');
  
          $data['q'] = $this-&gt;sales_model-&gt;getAll();
  
          $this-&gt;load-&gt;view('sales', $data);
      }
  }
  </code></pre>
  
  <p>-------------------- here is my view code ----------------</p>
  
  <pre><code>&lt;?php foreach($q as $row) : ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $row-&gt;id; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php $date = new DateTime("@$row-&gt;date"); echo $date-&gt;format('D M d, Y'); ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row-&gt;brand; ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $row-&gt;model; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <hr>
  
  <p>anybody help me, i want to get date from sales table and products detail who add in sales table.
  Thanks</p>