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 8889555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:17:25+00:00 2026-06-14T22:17:25+00:00

I have custom PHP site and using this script for pagination. echo Page <strong>$pagenum</strong>

  • 0

I have custom PHP site and using this script for pagination.

echo "Page <strong>$pagenum</strong> of <strong>$last</strong><br><br>";
    if ($pagenum == 1)
    {
    }
    else
        {
        echo "<li> <a href='{$_SERVER['PHP_SELF']}?pagenum=1'><strong>First page</strong></a></li>";
        echo " ";
        $previous = $pagenum-1;
        echo "<li> <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>".$previous."</a></li>";
        }

        echo "";


    if ($pagenum == $last)
        {           
        }
    else {
        $next = $pagenum+1;
        echo "  ....  <li><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'> ".$next."</a></li>";
        echo " ";
        echo "<li><a href='{$_SERVER['PHP_SELF']}?pagenum=$last'><strong>Last page</strong></a></li>";
    } 

This only shows last two pages, not even first page. How to customize it to display first 5 and last 5 pages.

  • 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. Editorial Team
    Editorial Team
    2026-06-14T22:17:27+00:00Added an answer on June 14, 2026 at 10:17 pm

    It all depends on where and how your pages are stored though! if you do that with a database, you would need to check if the $pagenum ( which we don’t see defined anywhere ) has previous/next pages… and based on that you draw you +/- 5 pages anchors! preferably doing some looping!

    On the other hand if you are not using any database and just want to show some content based on the ?pagenum=(number) which is what you seem to do here! you would need to get the current page via $_GET[‘pagenum’] once the user is on the new page! so that the content displays properly!

    $pagenum = isset( $_GET['pagenum'] ) ? intval($_GET['pagenum']) : 0;
    

    well then you simply do something like :

    echo "<a href=\"{$_SERVER['PHP_SELF']}?pagenum=$first\">first</a>";
    
    for ( $i = $pagenum-5; $i <= $pagenum+5; ++$i ) // check if the pages exist as well somewhere ;)
    {
        if ( $pagenum != $i ) 
        {
            echo "<a href=\"{$_SERVER['PHP_SELF']}?pagenum=".($i)."\">$i</a>";
        }
        else
        {
            echo "<a href=\"#\">Current</a>";
        }
    }
    
    echo "<a href=\"{$_SERVER['PHP_SELF']}?pagenum=$last\">last</a>";
    

    if that “method” is too basic to you have a look at this ones simple-php-mysql-pagination, how-to-paginate-data-with-php, basic-pagination

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP website with a custom page routing system. A php script
I have Drupal 7 site which is working fine. I added a custom PHP
We have a custom PHP/MySQL web application that gets updated and copied (using SFTP)
I have just launched a site (using Joomla and a custom template), which doesn't
Say I have a blogging site http://www.example.com using custom cms, and I want each
I have a web site done using codeigniter php framework and mysql, i have
I'm trying to build a simple custom search for a Wordpress site using PHP
I have a problem with my advertisements on the domain www.spiceygames.com (this site's using
Given that I have a custom PHP error handler already, does it make sense
I have a custom MVC PHP framework that has a router class, which calls

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.