How to select data five to five in sql

I need a page like a forum. Like at the bottom of the page, I have page numbers

1 2 3 .... 45 46 47 48

I want to get 5 comments per page. Therefore, I should receive comments (11-15) when the user clicks on page 3. or comments (41-45) when 9. is selected. How can i do this.

SELECT * FROM mytable //five by five

Note I think there should be an easy way in SQL commands (for example, ORDER BY somethingcould work on my problem?)

but all answers (PHP, Javascript) are welcome.

+3
source share
2 answers

This is much more pseudo code than a real SQL query:

SELECT * FROM comment LIMIT (5*{$page-1}),5;
+2
source

You can use the sql limit clause.

SELECT * FROM comment LIMIT 0,5

- , , - .

, :

SELECT * FROM comment LIMIT ((page_number-1)*5),5;

(1 2 3....), .

<a href="comment.php?page=5">5</a>

, sql.

$start = ($_GET['page'] - 1)*5;
$sql = "SELECT * FROM comment LIMIT $start,5";
0

All Articles