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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:58:24+00:00 2026-05-16T13:58:24+00:00

I have a pagination function that I use for my database search that limits

  • 0

I have a pagination function that I use for my database search that limits the results per page to 25. However, I have roughly 2300 entries and when someone does a search that queries a lot of results I end up with 90 or so pagination links at the bottom of my page. I would like to limit the pagination navigator to only show 10 pages at a time, adjusting accordingly with page spelunking.

I’m not quite sure how to adjust my script.

Any help would be greatly appreciated.

My current function is so:

$search_function is a javascript function for getting the proper URL, $classical_guitar is referring to images.

function generate_page_links($cur_page, $num_pages) {
  global $search_function, $classical_guitarL, $classical_guitarR;
  $page_links = '';

  // If this page is not the first page, generate the "previous" link
  if ($cur_page > 1) {
    $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page - 1) . "');\">" . $classical_guitarL . "</a> ";
  }
  else {
    $page_links .= '';
  }

  // Loop through the pages generating the page number links
  for ($i = 1; $i <= $num_pages; $i++) {
    if ($cur_page == $i) {
      $page_links .= ' ' . $i;
    }
    else {
      $page_links .= '<a href="javascript:' . $search_function . "('', '" . $i . "');\"> " . $i . "</a> ";
    }

  }

  // If this page is not the last page, generate the "next" link
  if ($cur_page < $num_pages) {
    $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page + 1) . "');\">" . $classical_guitarR . "</a> ";
  }
  else {
    $page_links .= '';
  }

  return $page_links;
}
  • 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-05-16T13:58:25+00:00Added an answer on May 16, 2026 at 1:58 pm

    Here, I’ve modified your function:

    <?php
    
    function generate_page_links($cur_page, $num_pages)
    {
        global $search_function, $classical_guitarL, $classical_guitarR;
        $page_links = '';
    
    
        // If this page is not the first page, generate the "previous" link
        if ($cur_page > 1)
        {
            $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page - 1) . "');\">" . $classical_guitarL . "</a> ";
        }
        else
        {
            $page_links .= '';
        }
    
        $pager_num = 7; // How many page number you wish to display to the left and right sides of the current page
        $index_start = ($cur_page - $pager_num) <= 0 ? 1 : $cur_page - $pager_num;
        $index_finish = ($cur_page + $pager_num) >= $num_pages ? $num_pages : $cur_page + $pager_num;
        if (($cur_page - $pager_num) > 1) { $page_links .= '...'; } // Display ... when there are more page items than $page_num
    
        // Loop through the pages generating the page number links
        // NOTE: I've modified the for index pointers here...
        for ($i = $index_start; $i <= $index_finish; $i++)
        {
            if ($cur_page == $i)
            {
                $page_links .= ' ' . $i;
            }
            else
            {
                $page_links .= '<a href="javascript:' . $search_function . "('', '" . $i . "');\"> " . $i . "</a> ";
            }
        }
    
        if (($cur_page + $pager_num) < $num_pages) { $page_links .= '...'; } // Display ... when there are more page items than $page_num
    
        // If this page is not the last page, generate the "next" link
        if ($cur_page < $num_pages)
        {
            $page_links .= '<a href="javascript:' . $search_function . "('', '" . ($cur_page + 1) . "');\">" . $classical_guitarR . "</a> ";
        }
        else
        {
            $page_links .= '';
        }
    
        return $page_links;
    }
    
    ?>
    

    Hope it is helpful…

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

Sidebar

Related Questions

I currently have pagination functionality that displays the total page count, but I was
I have created an AJAX function that is used with pagination links to load
I have a dataTable that uses pagination. Now when my page loads then my
I Need away to show two per page, and have a pagination at the
I have a site that displays items, 12 items per page and I can
I have a page that display some data. It is loaded from a database
I have an application with associations and will pagination the pages. The index page
I have set up the following: Database class ($db) Pagination class ($paginator) I am
I have been using solr search and now I am adding pagination via the
I'm placing an entire pagination script into a function so I can use it

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.