-3

I am creating my first ever project on the topic "online mobile store" on NETBEANS IDE using PHP and MySQL as backend, on a page products.php I want to display 1st 10 products, then by clicking on NEXT button next 10 products will display....

Please tell me how to do this?

Nick Dickinson-Wilde
  • 1,015
  • 2
  • 15
  • 21
  • 1
    Front-end can never be PHP, Here is an article about pagination system http://stackoverflow.com/questions/3705318/simple-php-pagination – Jacob Sep 09 '14 at 15:24

2 Answers2

2

You need to use the LIMIT sentence on the Mysql query, like this:

SELECT * FROM table LIMIT 0,10

The first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return

You will need to increase by 10 the first number using PHP.

For example, if you want the second page (from 10 to 20) your query should be:

SELECT * FROM table LIMIT 10,10

https://dev.mysql.com/doc/refman/5.0/en/select.html

0

First of all, PHP and MySQL are both backends. HTML/CSS/JS is for frontend.

Second, the thing is achieved by altering your query using LIMIT.

  • For first ten : mysql_query(".... LIMIT 0, 10");
  • For second ten: mysql_query(".... LIMIT 10, 20");
  • ... and so on

Where you get the START and OFFSET from your URL like this:

  • example.com/article.php?page=0 -> LIMIT 0, 10
  • example.com/article.php?page=1 -> LIMIT 10, 20

I leave the algorithm to you ;)

mariobgr
  • 2,143
  • 2
  • 16
  • 31