title: How to get data from a query back from the controller
body: <p>I have a question regarding on how I will retrieve the data that I query in my model to my controller and pass it in my view.</p>
  
  <p>Controller:</p>
  
  <pre><code>class View_book_controller extends CI_Controller {
  
  function __construct() {
  
      parent::__construct();
      $this-&gt;load-&gt;helper('cookie');
      $this-&gt;load-&gt;helper('url');
      $this-&gt;load-&gt;library('session');
  }
  
  function loadView() {
      $this-&gt;load-&gt;model('view_book_model');
      $postlist['studentID'] = $this-&gt;input-&gt;get_post('studentID');
  
      $this-&gt;view_book_model-&gt;getBookList();
  
      $this-&gt;load-&gt;view('viewbooks.php', $postlist);
   }
  }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code>class View_book_model extends CI_Model {
  
  function getBookList() {
  
      $query = $this-&gt;db-&gt;query("SELECT * from books");
  
      if($query-&gt;num_rows() &gt; 0 ) {
          return true;
      }
      else {
          return false;
      }
  }
  }
  </code></pre>
  
  <p>and here is the view for it. I want to put the data in a table and view it like a list.</p>
  
  <pre><code> &lt;!DOCTYPE HTML&gt;
   &lt;html&gt;
  
   &lt;head&gt;
   &lt;meta charset='UTF-8'&gt;
  
  &lt;link rel="stylesheet" href="&lt;?=base_url(); ?&gt;/public/css/tables.css"/&gt;
  
  &lt;script src="&lt;?=base_url()?&gt;/public/js/jquery.js"&gt;&lt;/script&gt;
   &lt;/head&gt;
  
  &lt;body&gt;
      &lt;input type="hidden" value = "&lt;?php echo $studentID; ?&gt;"/&gt;
      &lt;h3&gt; Search books &lt;/h3&gt;
      &lt;input type="text"&gt; &lt;/input&gt;
      &lt;input type="submit" value="Search"&gt; &lt;/input&gt;
      &lt;br&gt;&lt;br&gt;
  
      &lt;?php
          echo '&lt;hr&gt;';
          echo '&lt;h3&gt; Book List &lt;/h3&gt;';
          echo '&lt;table id="maintable"  class="table"&gt;';
  
              echo '&lt;th&gt; Book ID&lt;/th&gt;';
              echo '&lt;th&gt; Book Title &lt;/th&gt;';
              echo '&lt;th&gt; Book Author &lt;/th&gt;';
              echo '&lt;th&gt; Quantity &lt;/th&gt;';
              echo '&lt;th&gt; On-hand &lt;/th&gt;';
  
              echo '&lt;tr&gt;
                      &lt;td&gt;1&lt;/td&gt;
                      &lt;td&gt;An Abundance of Katherine&lt;/td&gt;
                      &lt;td&gt;John Green&lt;/td&gt;
                      &lt;td&gt;10&lt;/td&gt;
                      &lt;td&gt;5&lt;/td&gt;
                   &lt;/tr&gt;';
          echo '&lt;/table&gt;';
      ?&gt;
  &lt;/body&gt;
   &lt;/html&gt;
  </code></pre>