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

  • SEARCH
  • Home
  • 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 92881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:15:25+00:00 2026-05-10T23:15:25+00:00

So I’m doing this in PHP but it is a logic issue so I’ll

  • 0

So I’m doing this in PHP but it is a logic issue so I’ll try to write it as generically as possible.

To start here’s how this pagination script works:

  1. for (draw first three pages links)
  2. if (draw ellipsis (…) if there are pages between #1’s pages and #3’s pages)
  3. for (draw current page and two pages on each side of it links)
  4. if (draw elipsis (…) if there are pages between #3’s pages and #5’s pages)
  5. for (draw final three pages links)

The problem is that when there are low amounts of pages (I noticed this when the page count was at 10) there should be an ellipsis but none is drawn.

Onto the code:

$page_count = 10; //in actual code this is set properly $current_page = 1; //in actual code this is set properly  for ($i = 1;$i <= 3;$i++) {     if ($page_count >= $i)         echo $i; }  if ($page_count > 3 && $current_page >= 7)     echo '...';  for ($i = $current_page - 2;$i <= current_page + 2;$i++) {     if ($i > 3 && $i < $page_count - 2)         echo $i; }  if ($page_count > 13 && $current_page < $page_count - 5)     echo '...';  for ($i = $page_count - 2;$i <= $page_count;$i++) {     if ($page_count > 3)         echo $i; } 

So I figure the best idea would to be to modify one of the two ellipsis if statements to include a case like this, however I’ve tried and am stumped.

Also please note that I condensed this code for readability sake so please don’t give tips like ‘those for loops are ineffective because they will recalculate current_page – 2 for each iteration’ because I know 🙂


For those whom want to see a breakdown of how this logic currently works, here is example output ( modified ) with iterating $page_count and $current_page. http://rafb.net/p/TNa56h71.html

  • 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-10T23:15:25+00:00Added an answer on May 10, 2026 at 11:15 pm
    <?php  /**  * windowsize must be odd  *  * @param int $totalItems   * @param int $currentPage   * @param int $windowSize   * @param int $anchorSize   * @param int $itemsPerPage   * @return void  */ function paginate($totalItems, $currentPage=1, $windowSize=3, $anchorSize=3, $itemsPerPage=10) {     $halfWindowSize = ($windowSize-1)/2;      $totalPages = ceil($totalItems / $itemsPerPage);     $elipsesCount = 0;     for ($page = 1; $page <= $totalPages; $page++) {         // do we display a link for this page or not?         if ( $page <= $anchorSize ||               $page > $totalPages - $anchorSize ||             ($page >= $currentPage - $halfWindowSize &&             $page <= $currentPage + $halfWindowSize) ||             ($page == $anchorSize + 1 &&              $page == $currentPage - $halfWindowSize - 1) ||             ($page == $totalPages - $anchorSize &&                $page == $currentPage + $halfWindowSize + 1 ))         {             $elipsesCount = 0;             if ($page == $currentPage)                 echo '>$page< ';             else                 echo '[$page] ';         // if not, have we already shown the elipses?         } elseif ($elipsesCount == 0) {             echo '... ';             $elipsesCount+=1; // make sure we only show it once         }     }     echo '\n'; }  // // Examples and output //  paginate(1000, 1, 3, 3); // >1< [2] [3] ... [98] [99] [100]   paginate(1000, 7, 3, 3); // [1] [2] [3] ... [6] >7< [8] ... [98] [99] [100]   paginate(1000, 4, 3, 3); // [1] [2] [3] >4< [5] ... [98] [99] [100]   paginate(1000, 32, 3, 3); // [1] [2] [3] ... [31] >32< [33] ... [98] [99] [100]   paginate(1000, 42, 7, 2); // [1] [2] ... [39] [40] [41] >42< [43] [44] [45] ... [99] [100]  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • 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 Firstly, there are limitations to what you can do, once… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer You can probably write something similar to webkit2png, unless your… May 11, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer Setting the width on the ul element should do the… May 11, 2026 at 4:41 pm

Related Questions

So I'm getting a new job working with databases (Microsoft SQL Server to be
So I have a Sybase stored proc that takes 1 parameter that's a comma
So I'm embarking on an ASP.NET MVC project and while the experience has been
So I've got a JPanel implementing MouseListener and MouseMotionListener : import javax.swing.*; import java.awt.*;
So I wrote some perl that would parse results returned from the Amazon Web

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.