SnakZ Posted January 30, 2011 Share Posted January 30, 2011 i been trying to find out how does a forum do this what code is needed ? im trying to do what a forum would do show 12 post on the first page then give you a "go to page" that list the next 12 or whatever just like a forum word after looking at forum codes i cant tell how they do it lol Link to comment https://forums.phpfreaks.com/topic/226137-how-to-make-go-to-page-1238910/ Share on other sites More sharing options...
Pikachu2000 Posted January 30, 2011 Share Posted January 30, 2011 What you're looking for is called pagination. There's a tutorial on the main site. Link to comment https://forums.phpfreaks.com/topic/226137-how-to-make-go-to-page-1238910/#findComment-1167374 Share on other sites More sharing options...
QuickOldCar Posted January 30, 2011 Share Posted January 30, 2011 I made 2 types of pagination. The first can do any posts amount, the second I hardcoded set to 10 posts per page, takes more math to predetermine the pages which I didn't need can see them both working and the codes embed below them. http://get.blogdns.com/paginate and this http://get.blogdns.com/dynaindex/paginate.php Basically it controls the limit in a mysql query determined by what current page you are on Link to comment https://forums.phpfreaks.com/topic/226137-how-to-make-go-to-page-1238910/#findComment-1167415 Share on other sites More sharing options...
nankoweap Posted January 31, 2011 Share Posted January 31, 2011 i been trying to find out how does a forum do this what code is needed ? i'm assuming you know how to paginate your data and simply want to know how to the create the page links. i wrote the function below. simply pass in the current page number, the total number of pages and the url to go to when each page is clicked. the function appends a page variable, pg, to the end of url. it returns the HTML for the page numbers. public function pageLinks($pageNumber, $pageCount, $url) { $pl = "Total Pages: $pageCount<br/>"; $multiples = ceil($pageCount / 10); $theMultiple = ceil($pageNumber / 10); $qSep = strpos($url, '?') ? '&' : '?'; // newer elements available? if ($theMultiple > 2) { $pl .= "<a href='${url}${qSep}pg=1'>< Newest</a> "; } if ($theMultiple > 1) { $pl .= "<a href='${url}${qSep}pg=" . ((($theMultiple-2) * 10) + 1) . "'>< Newer</a> "; } // current multiple $startPage = (($theMultiple - 1) * 10) + 1; $endPage = min($theMultiple * 10, $pageCount); for ($i = $startPage; $i <= $endPage; $i++) { $pl .= " " . (($pageNumber == $i) ? "<b>$i</b>" : "<a href='${url}${qSep}pg=$i'>$i</a>"); } $pl .= " "; // older elements available? if ($theMultiple < $multiples) { $nextMultiple = ($theMultiple * 10) + 1; $pl .= "<a href='${url}${qSep}pg=" . $nextMultiple . "'>Older ></a> "; } if ($theMultiple < $multiples - 1) { $pl .= "<a href='${url}${qSep}pg=$pageCount'>Oldest ></a>"; } return $pl; } // pageLinks Link to comment https://forums.phpfreaks.com/topic/226137-how-to-make-go-to-page-1238910/#findComment-1167587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.