The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

What that code does is query the mysql table and then counts how many results there are. Then it takes that number and divides it by how many results are going to be on each page, and that gives you a number. We then make that number into an integer so that we can know exactly how many pages there are. If the original number isn't an integer, then we know it wasn't a whole number so we need to add one to the page number and then we display each page number onto the page.

Note that the code will only display the page numbers and not the results for each page. You have to use a SELECT statement with the text "LIMIT $start,$stop" at the very end of the query, with $start equalling the result number to start from and $stop equalling the result number to end with. Remember, the results always start from 0, so you could use "Select variables FROM table LIMIT 0,10" to display to results per page.

In the previous code I just gave you, we divided the total number of results by the amount on each page. So it counted 25 results, and if you had 10 results per page, it would get the value of 2.5. But, it can't stay like that because we need the total amount of pages to be a whole number, so we turn it into an integer which makes "2.5" into just "2", but that isn't true because in reality, we will need 3 pages and not just 2. We then see if the original number was a whole number and if it wasn't, we add "1" to the new "integer" number which then makes the total number of pages "3", which is correct.