title: Fetch data from database in codeigniter
body: <p>I have 2 cases where i am fetching the entire data and total number of rows of a same table in codeigniter, I wish to know that is there a way through which i can fetch total number of rows, entire data and 3 latest inserted records from the same table through one code</p>
  
  <blockquote>
    <p>Controller code for both cases is as given below (although i am applying it for each case seperately with different parameters)</p>
  </blockquote>
  
  <pre><code>public function dashboard()
      {
          $data['instant_req'] = $this-&gt;admin_model-&gt;getreq();
          $this-&gt;load-&gt;view('admin/dashboard',$data);
      }
  </code></pre>
  
  <p>1) to fetch the entire data from a table in codeigniter</p>
  
  <p>Model Code</p>
  
  <pre><code>public function getreq()
      {
          $this-&gt;db-&gt;where('status','pending');
          $query=$this-&gt;db-&gt;get('instanthire');
          return $query-&gt;result();
      }
  </code></pre>
  
  <p>View Code</p>
  
  <pre><code>foreach ($instant_req as $perreq) 
      {
          echo $perreq-&gt;fullname;
          echo "&lt;br&gt;";
      }
  </code></pre>
  
  <p>2) to fetch number of rows from a table in codeigniter</p>
  
  <pre><code>public function getreq()
      {
          $this-&gt;db-&gt;where('status','pending');
          $query=$this-&gt;db-&gt;get('instanthire');
          return $query-&gt;num_rows();
      }
  </code></pre>
  
  <p>View Code</p>
  
  <pre><code>echo $instant_req;
  </code></pre>