title: Fetching data from 2 tables using codeigniter
body: <p>I got this tables:"Study","Users","Subjects".</p>
  
  <blockquote>
    <p>"Study" includes:<strong>(id, user_id[is the foreign key to the column "id" of the table "Users"], subject_id[is the foreign key to the column "id" of the table "Subjects"], grade, date)</strong></p>
    
    <p>"Users" includes:<strong>(id,username,name,lastname,password,type,status,date)</strong></p>
    
    <p>"Subjects" includes:<strong>(id, career_id, name, description, hours)</strong></p>
  </blockquote>
  
  <p>I wanna get something like this at the end:</p>
  
  <p><a href="https://i.stack.imgur.com/dn8u3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dn8u3.png" alt="enter image description here"></a></p>
  
  <p>Dont know what to do at the crudmodel/controller files to get the usernames, subjects names :S</p>
  
  <p>This is my codeigniter code (my view file):</p>
  
  <pre><code>                    &lt;thead&gt;
                      &lt;th&gt;id&lt;/th&gt;
                      &lt;th&gt;User&lt;/th&gt;
                      &lt;th&gt;Subject&lt;/th&gt;
                      &lt;th&gt;Grade&lt;/th&gt;
                      &lt;th&gt;Date&lt;/th&gt;
                      &lt;th&gt;Action&lt;/th&gt;
                  &lt;/thead&gt;
  
  &lt;tbody&gt;
      &lt;?php
  
      if (count($records) &gt; 0 &amp;&amp; $records != false) {
          foreach($records as $record) {
  
              echo "&lt;tr&gt;
                        &lt;td&gt;".$record-&gt;id."&lt;/td&gt;
                        &lt;td&gt;".$record-&gt;user."&lt;/td&gt;
                        &lt;td&gt;".$record-&gt;subject."&lt;/td&gt;
                        &lt;td&gt;".$record-&gt;grade."&lt;/td&gt;
                        &lt;td&gt;".$record-&gt;date."&lt;/td&gt;
                        &lt;td align='center'&gt;
                          &lt;a href='".site_url('Home/edit')."/$record-&gt;id'&gt; 
                           &lt;button type='button' class='btn btn-primary'&gt;EDIT&lt;/button&gt;&lt;/a&gt; |
                          &lt;a href='".site_url('Home/delete')."/$record-&gt;id'&gt; 
                           &lt;button type='button' class='btn btn-danger'&gt;DELETE&lt;/button&gt;&lt;/a&gt;
  
                    &lt;/tr&gt;";
          }
  
         }
      ?&gt;
  
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Here my controller file:</p>
  
  <pre><code>  class Home extends CI_Controller{
  
       public function __construct(){
           parent::__construct();
  
           $this-&gt;load-&gt;model("Crudmodel");
  
      }
      public function index(){
  
          $data['records'] = $this-&gt;Crudmodel-&gt;getRecords();
  
          $this-&gt;load-&gt;view('home', $data);
  
      }
  </code></pre>
  
  <p>My crudmodel:</p>
  
  <pre><code>class Crudmodel extends CI_Model{
  
      public function __construct(){
       parent::__construct();
  
       $this-&gt;load-&gt;database();
  
      }
  
      public function getRecords(){
  
          $this-&gt;db-&gt;select()//DONT KNOW WHAT TO DO
                   -&gt;from()
                   -&gt;join();
  
          $q = $this-&gt;db-&gt;get();
  
          if($q -&gt; num_rows() &gt; 0){
  
              return $q-&gt;result();
          }
  
          return false;
  
      }
  </code></pre>
  
  <p>Hope you can help me</p>