mysql: select last 10 rows from DESC LIMIT

mysql, php

Solution

You are LIMITing using just one parameter. But you can use `LIMIT x,y` to specify both `x` (the position of the first record to return) and `y` (the number of records to return).

Pass a variable to the page like `results.php?start=x` to set a starting position.

if (!isset( $_REQUEST['start'] ) ) { $start = 0; } else { $start = (int)$_REQUEST['start']; }

mysql_query("SELECT title,id,alt_name FROM dle_post WHERE approve='1' AND date >= '$monthagodate'
AND date < '$curdate' + INTERVAL 1 day ORDER BY date DESC LIMIT $start,10;");

And then you can generate a link to the next page like so:

`echo '<a href="results.php?start=' . ($_REQUEST['start']+10) . '">Next 10 results</a>';`

Problem

i'm working on a block which will display last 10 posts, when user clicks on "load more" button i would like to display 10 older posts. how can i select last 10 rows if i'm already using DESC LIMIT? ``` mysql_query("SELECT title,id,alt_name FROM dle_post WHERE approve='1' AND date >= '$monthagodate' AND date < '$curdate' + INTERVAL 1 day ORDER BY date DESC LIMIT $more;"); ```

Original source