Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter - retrieving all posts except the last from table

My scenario:

  • I want to post all threads from a table in my DB, except for the very last one. I've tried to use select_max, but it doesn't work. I can't seem to figure out what to put in my query string.

I just want to retrieve all posts and offset it by 1.

like image 869
Myung Ki Avatar asked Sep 16 '26 02:09

Myung Ki


1 Answers

Something like this might work:

SELECT * FROM table ORDER BY id DESC LIMIT 100,1 (limit 100, offset by 1)

or you get all the posts and in when looping through them in codeigniter you could do something like this:

$i = 1;
foreach($posts as $p):
    if($i != 1):
        //show posts
    endif;
$i++;
endforeach;
like image 173
Christophe Avatar answered Sep 17 '26 17:09

Christophe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!