SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: PHP Paging

  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Location
    Pretoria, South Africa
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Paging

    Hi.

    This is most likely an easy fix but I can't seem to find the answer. I have a page which display data and then a whole lot of pages for example:
    << 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 >>

    The problem is that I can't seem to limit the number of pages displyed. I would like to display it like this
    << ...5 6 7 8 9 10 11 12 13... >>

    Help would be appreciated.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If you have a $currentpage variable then it's a case of using simple maths. Make a for loop like this:
    PHP Code:
    for ($i currentpage 4$j $currentpage 5$i $j$i++) {
      echo 
    "<a href=\"?page=$i\">$i</a>";

    You should also include a facility for going to the first and last pages. The first is easy, the last will require you having a $numberofpages variable.

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Location
    Pretoria, South Africa
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx... didn't know you could put more that on condition in a for loop.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •