One question. How do the script knows what is the current page? I am thinking about this section:
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
First I thought that there’s probably a php function called currentpage, but that does not seem to be true. So how do the script knows what is the current page?
Have a quick look on Sitepoint for pagination. Rather than running what your doing which is essentially the same MySQL query, you need to add another factor to your limiting - think of it like this:
You have 67 articles (for arguments sake) in your database. You count them, using the count statement you showed us earlier. Now, work out how many articles you want - commonly, and what you are looking at: 10.
Therefore, with a bit of maths (and rounding up article number / page number) we reach 7 pages. We can then run a MySQL query, based on which page we are on of pagination, and LIMIT this, by setting two limits, like so:
SELECT id, number FROM numbers LIMIT $offset, $rowsperpage
Where offset is how many articles have gone by, and rowsperpage is your number, 10, which becomes:
I tested the code at phpfreaks and it works just fine as long as I put it on the same php page. My webpage is built up in another way.
On the index.php I have a menu link i the navigation area, Archive, and if you click it it will include a file with the code from php builder. The page will show the first 10 items in the content area of the index page. I also get the pagination links which makes it possible to look at the next 10 items and so forth. The problem is that the pagination links dont work. If i click a pagination link it does not show me 10 more items, instead it will show the index.php page. I guess it is this that causes the problem: