title: How do you get data from multiple tables using Active Record Class in CodeIgniter
body: <p>I'm trying to learn how to extract data from multiple tables and put them into a variable and return them to my controller.</p>
  
  <p>I can get information from one single table like this:</p>
  
  <pre><code>            $this-&gt;db-&gt;select('first_name, last_name');
              $this-&gt;db-&gt;from('people');
              $this-&gt;db-&gt;where('first_name', $firstname);
              $this-&gt;db-&gt;where('last_name', $lastname);
              $result = $this-&gt;db-&gt;get();
  </code></pre>
  
  <p>but I'm confused as to how I can get data from another table and match them with other variables holding more of the users input.</p>
  
  <p>I've read the Active Record documentation on the CI website but the only thing I found that could be what I'm looking for is the join() query, but I don't how to use it, the example doesn't help on the website because I don't understand this:</p>
  
  <pre><code>$this-&gt;db-&gt;join('comments', 'comments.id = blogs.id');
  </code></pre>
  
  <p>Does 'comments' mean the table 'comments'? And if you were comparing a variable with comments.id, would you have to include the variable outside of the single quotes like this: <code>'comments.id =' $blogid</code> ?</p>
  
  <p>Or can I do this: query from one table and put those results in a variable as follows:</p>
  
  <pre><code>$result1 = $this-&gt;db-&gt;get();
  </code></pre>
  
  <p>and then again do another query from the other table and put that in </p>
  
  <pre><code>$result2
  </code></pre>
  
  <p>Then I can say: <code>$query = $result1 + $result2;</code></p>
  
  <p>Is that possible?</p>
  
  <p>If someone could please confirm this information/help me out I would be greatful. Thanks</p>