Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 149989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:13:08+00:00 2026-05-11T09:13:08+00:00

<< 1 2 3 4 … 15 16 17 … 47 48 49 50

  • 0

<< 1 2 3 4 … 15 16 17 … 47 48 49 50 >>

<< 1 2 3 4 5 6 7 … 47 48 49 50 >>

<< 1 2 3 4 … 44 45 46 47 48 49 50 >>

(the bold is the selected page)

Is there any cleaver logic out there that creates scaling pagination like this? I have created one of these before but it ended up as a mess of logic statements.

The language i am doing this in now is PHP but if you have examples or tips for any language, it would be appreciated.

By scaling i mean when there are only a few pages. The pagination displays this.

<< 1 2 3 4 5 6 7 >>

As the number of pages grow to a certain point, the pagination stops showing all numbers and starts splitting them up.

<< 1 2 3 4 … 47 48 49 50 >>

<< 1 2 3 4 5 6 … 47 48 49 50 >>

<< 1 2 3 4 5 6 7 8 … 47 48 49 50 >>

<< 1 2 3 4 .. 7 8 9 … 47 48 49 50 >>

<< 1 2 3 4 .. 15 16 17 … 47 48 49 50 >>

<< 1 2 3 4 … 44 45 46 47 48 49 50 >>

<< 1 2 3 4 … 47 48 49 50 >>

(note, the actual numbers and how many it shows before and after is not relevant)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:13:08+00:00Added an answer on May 11, 2026 at 9:13 am

    Sorry for the blob of code but here goes. Hopefully the comments are enough to tell you how it works – if leave a comment and I might add some more.

        /**      * Get a spread of pages, for when there are too many to list in a single <select>      * Adapted from phpMyAdmin common.lib.php PMA_pageselector function      *      * @param integer total number of items      * @param integer the current page      * @param integer the total number of pages      * @param integer the number of pages below which all pages should be listed      * @param integer the number of pages to show at the start      * @param integer the number of pages to show at the end      * @param integer how often to show pages, as a percentage      * @param integer the number to show around the current page      */     protected function pages($rows, $pageNow = 1, $nbTotalPage = 1, $showAll = 200, $sliceStart = 5, $sliceEnd = 5, $percent = 20, $range = 10)     {         if ($nbTotalPage < $showAll)             return range(1, $nbTotalPage);          // Always show the first $sliceStart pages         $pages = range(1, $sliceStart);          // Always show last $sliceStart pages         for ($i = $nbTotalPage - $sliceEnd; $i <= $nbTotalPage; $i++)             $pages[] = $i;          $i = $sliceStart;         $x = $nbTotalPage - $sliceEnd;         $met_boundary = false;         while ($i <= $x)         {             if ($i >= ($pageNow - $range) && $i <= ($pageNow + $range))             {                 // If our pageselector comes near the current page, we use 1                 // counter increments                 $i++;                 $met_boundary = true;             }             else             {                 // We add the percentate increment to our current page to                 // hop to the next one in range                 $i = $i + floor($nbTotalPage / $percent);                  // Make sure that we do not cross our boundaries.                 if ($i > ($pageNow - $range) && !$met_boundary)                   $i = $pageNow - $range;             }              if ($i > 0 && $i <= $x)                 $pages[] = $i;         }          // Since because of ellipsing of the current page some numbers may be double,         // we unify our array:         sort($pages);         return array_unique($pages);     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 86k
  • Answers 86k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The easiest thing to do would be to include the… May 11, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer That's virtual inheritance, you do it when you know you'll… May 11, 2026 at 5:17 pm
  • Editorial Team
    Editorial Team added an answer Put the following to your .bashrc shopt -s extglob It… May 11, 2026 at 5:17 pm

Related Questions

<< 1 2 3 4 ... 15 16 17 ... 47 48 49 50
List<int> a = 1,2,3 List<int> b = 2,4,5 output 1,3,4,5
I've always understood that each number in the version (ex: 1.2.3.4) is treated as
By which I mean this: Given the input set of numbers: 1,2,3,4,5 becomes 1-5.
Given this input: [1,2,3,4] I'd like to generate the set of spanning sets: [1]

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.