Hi there, I need PHP pagination Code. Can someone give me this code. Thanks for your attention. Thanks
What are you basing the pagination on? Do you wanna fetch records from a database? Parse an array? Divide a string?
I want to display 20 products in each page. so I need this code. Thanks for replying my answer.Thanks
I'm assuming you're fetching the results from a database - the simplest way of doing this is using a GET-parameter (for pages) and LIMIT the returns from the database. Say you have something like this to fetch records from the database: SELECT * FROM products Code (markup): to fetch the first 20 records, you'd do this: SELECT * FROM products LIMIT 0, 20 Code (markup): to get the next 20 records, you'd do this: SELECT * FROM products LIMIT 20, 40 Code (markup): and so forth and so on. To do this via PHP you'd do something like this: $page = isset($_GET['page]) ? $_GET['page'] : 0; // what this does is see if the ?page=-parameter is set in the URL, and if it is, assign the value to $page $records = ($page != 0 || !empty($page)) ? $page * 20 : 0; $limit = ($page != 0 || !empty($page)) ? $page * 20 * 2 : 20; // this tells you which limit to use // then you build your query like this: SELECT * FROM products LIMIT $page, $limit; PHP: You'll of course also need a way to go through the total pages, something like loop through the total records found and create a list of links of pages (1 to whatever number you reach)