Welcome Guest, Not a member yet? Register   Sign In
In Model how to select all last data starting from 5th row ?

For examle there is 10 rows in table. My issue is how to fetch all data but starting from 5th row and 4 3 2 1 and so on?
Below code works but only with id numbers. so when my datas in table id will be mixed up like 50 46 42 40 and so on that code wont work.

public function fetch_data() {
       $this->db->where('site_id <',$maxid);
       $this->db->order_by('site_id', 'DESC');
       $query = $this->db->get("sites");

       if ($query->num_rows() > 0) {
           foreach ($query->result() as $row) {
               $data[] = $row;
           return $data;
       return false;

Remove the "where" clause and use "limit" :


(12-07-2014, 07:11 PM)includebeer Wrote: Remove the "where" clause and use "limit" :

thank you for reply
if if use limit(5) result will give me last 5 rows but my question is quite different. and yesterday i found solution for that

added following code in
$q = $this->db->query('SELECT site_id FROM sites ORDER BY site_id DESC LIMIT 1');

$row = $q->row();
$b = $row->site_id+1-5;
$this->db->where('site_id <',$b);

and worked like a charm

Theme © iAndrew 2016 - Forum software by © MyBB