The best page divider

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

The best page divider

Post by phice »

This is the most accurate way to figure out how many pages you need to display by the number posts (or whatever) into a resullting number of pages.

Code: Select all

function numpages($numposts, $limitposts) {
	(($numposts % $limitposts) == 0) ? $numpages = ($numposts / $limitposts) : $numpages = (floor($numposts / $limitposts) + 1);
	return $numpages;
}

echo numpages(185, 35);

// result: 6
I'm using this in my forum and it's as accurate as you can get. Hope this helps in your coding adventures. 8)
Post Reply