Jump to content

how to make: Go To Page 1,2,3....8,9,10


SnakZ

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.