Make multiple pages from mysql query

So, I have this database on the right, with some fields called "id", "title" and "message". Now I have received about 700 messages in the database. So all I want to do is limit the maximum number of posts per page and the maximum number of pages ... How can I do this?

I only know to get the first page using LIMIT...

+3
source share
2 answers

As you may have guessed, you should use a keyword . LIMIT

It takes two meanings (citation):

  • first line offset to return
  • maximum number of rows to return


- :

select * from your_table order by ... limit 0, 50

, :

select * from your_table order by ... limit 50, 50

:

select * from your_table order by ... limit 100, 50

; -)


:, , URL-, :

http://www.example.com/page.php?pagenum=2

:

$offset = 50 * intval($_GET['pagenum']);

:

select * from your_table order by ... limit $offset, 50


URL- URL-:

http://www.example.com/page.php?pagenum=0
http://www.example.com/page.php?pagenum=1
http://www.example.com/page.php?pagenum=2
...

, 700 50 , 700/50 ;-)
, - :

for ($i=0 ; $i<700/50 ; i++) {
    // Use http://www.example.com/page.php?pagenum=$i as URL
}


, 700 - , , , : count:

select count(*) as total
from your_table
...
+9

PHP GET, .

LIMIT ($ page_number * $messages_per_page), $messages_per_page ().

$messages_per_page = 50 . $page_number GET , 0.

0

Source: https://habr.com/ru/post/1794937/


All Articles