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
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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.