title: 2 join conditions codeigniter giving error
body: <p>I have 2 tables - for orders and for documents for these orders. I want to show all orders from first table and if there are documents for these orders, to show date of documents(I take date from table <code>documents</code>). 
  I'm trying to make 2 join conditions because in table <code>documents</code> if I only join on idOrder, there are more than 1 row and I have to join on documents.name to be same as $this->uri->segment(3).
  But I'm using the following code and it gives me error. Could I use 2 join conditions in this way:</p>
  
  <p>My model is:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
   public function get_all_orders($user_id){
  
          $this-&gt;db-&gt;select('ordersheader.*, customer.name as customerName,documents.date_make');
          $this-&gt;db-&gt;from('ordersheader');
          $this-&gt;db-&gt;join('customer', 'ordersheader.idCustomer = customer.idCustomer');
          $this-&gt;db-&gt;join('documents', 'ordersheader.idOrder = documents.idOrder','left'); 
          $this-&gt;db-&gt;join('documents as D', 'D.name="declaration"','left'); 
  
  
          $this-&gt;db-&gt;where('ordersheader.user_id', $user_id);
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result_array();
      }
  </code></pre>
  
  <p>Edited: I found solution. But it's written in pure sql, how to write it with Codeingiter syntax? My new working code is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
   $query=("SELECT ordersheader.*, customer.name as customerName,documents.date_make,documents.deactivated_at
              FROM ordersheader JOIN customer ON  ordersheader.idCustomer = customer.idCustomer
              LEFT JOIN documents
              ON ordersheader.idOrder = documents.idOrder AND documents.name = '".$document."' 
              WHERE ordersheader.user_id = '".$user_id."' ");
   $result = $this-&gt;db-&gt;query($query);
        return $result-&gt;result_array(); </code></pre>
  </div>
  </div>
  </p>