title: SQL join in CodeIgniter with Active Record
body: <p>I'm trying to wrap my head around this, but I seem to go in circles. I'm trying to list a users topics one by one, with the quotes belonging to that specific topic underneath. If that makes sense.</p>
  
  <p>I have 3 tables, like so:</p>
  
  <blockquote>
    <p>[USERS] user_id username</p>
    
    <p>[TOPICS] topic_id user_id topic_name</p>
    
    <p>[QUOTES] quote_id topic_id quote_name</p>
  </blockquote>
  
  <p>I want to be able to do something like this in my view:</p>
  
  <blockquote>
    <p>Username: Thomas</p>
    
    <blockquote>
      <p>Topic 1: Whatever</p>
      
      <p>Quotes: One quote, another quote, and a third quote, all belonging to Topic 1.</p>
      
      <p>Topic 2: Another topic from Thomas</p>
      
      <p>Quotes: Yes indeed, Okay thanks, I love Stack Overflow, These quotes belong to Topic 2.</p>
    </blockquote>
  </blockquote>
  
  <p>But I can't get it to work, I've been trying everything, including weird stuff like:</p>
  
  <pre><code>public function get_quotes()
  {
  
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('topics');
      $this-&gt;db-&gt;join('quotes', 'topic_id = quote_id');
  
      $query = $this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows() &gt; 0)
      {
          foreach ($query-&gt;result() as $row) {
              $data[] = $row;
          }
      }
      return $data;
  }
  </code></pre>
  
  <p>Is this strange, should I instead try using 'where' instead? Something like: </p>
  
  <pre><code>$this-&gt;db-&gt;where('user', $user_id);
  $this-&gt;db-&gt;where('topic', $topic_id);
  $this-&gt;db-&gt;where('quote', $quote_id);
  </code></pre>
  
  <p>I really appreciate any help I can get, or just a finger pointed in the right direction!</p>