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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:23:50+00:00 2026-05-13T18:23:50+00:00

I am trying to make my pagination script a bit more dynamic and am

  • 0

I am trying to make my pagination script a bit more dynamic and am needing some help with the calculating of the page numbers part.

I have this script below which calculates the number of pages using php, however I would like to add other buttons that when clicked will filter and sort out data which means the pagination numbers need to be calculated again.

The script I have does not allow for this to happen, so I am wondering if there is a more efficient/dynamic way of calculating the pagination numbers then the way I am doing it now.

This is the main page (pagination.php)

<?php
include('config.php');
$per_page = 3;

//Calculating no of pages
$sql = "select * from explore";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page)
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1``   /jquery.min.js"></script>
<script type="text/javascript" src="jquery_pagination.js"></script>


<div id="loading" ></div>
<div id="content" data-page="1"></div>
<ul id="pagination">
<?php
//Pagination Numbers
for($i=1; $i<=$pages; $i++)
{
    echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
}
?>

</ul>
<br />
<br />

And here is the JS script (jquery.pagination.js)

$(document).ready(function(){

    //Display Loading Image
    function Display_Load()
    {
        $("#loading").fadeIn(900,0);
        $("#loading").html("<img src='bigLoader.gif' />");
    }

    //Hide Loading Image
    function Hide_Load()
    {
        $("#loading").fadeOut('slow');
    };

    //Default Starting Page Results
    $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

    Display_Load();

    $("#content").load("pagination_data.php?page=1", Hide_Load());

    //Pagination Click
    $("#pagination li").click(function(){
        Display_Load();

        //CSS Styles
        $("#pagination li")
            .css({'border' : 'solid #dddddd 1px'})
            .css({'color' : '#0063DC'});

        $(this)
            .css({'color' : '#FF0084'})
            .css({'border' : 'none'});

        //Loading Data
        var pageNum = this.id;

        $("#content").load("pagination_data.php?page=" + pageNum, function(){
            Hide_Load();
            $(this).attr('data-page', pageNum);
        });
    });
});

I tried to put the calculation part of the script in ‘pagination_data.php’ file so when I clicked a button or link to go to that page it would generate everything, but it did not work.

So, any help on figuring out a good way of doing this would be great. Thanks.

  • 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-13T18:23:50+00:00Added an answer on May 13, 2026 at 6:23 pm

    Your page generation code is fine, it’s the fixed query that it’s using that needs to be changed. I would suggest changing your pagination code into a function that takes an $sql parameter so that you could pass in the correct query adjusted by any filters:

    function generate_pagination($sql) {
      include_once('config.php');
      $per_page = 3;
    
      //Calculating no of pages
      $result = mysql_query($sql);
      $count = mysql_num_rows($result);
      $pages = ceil($count/$per_page)
    
      //Pagination Numbers
      for($i=1; $i<=$pages; $i++)
      {
        echo '<li class="page_numbers" id="'.$i.'">'.$i.'</li>';
      }
    }
    

    and then call it like this:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1``   /jquery.min.js"></script>
    <script type="text/javascript" src="jquery_pagination.js"></script>
    
    <div id="loading" ></div>
    <div id="content" data-page="1"></div>
    <ul id="pagination">
    <?php generate_pagination('SELECT * FROM explore'); ?>
    </ul>
    <br />
    <br />
    

    or with a filter:

    <?php generate_pagination('SELECT * FROM explore WHERE key="value"'); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to make the pagination plugin work with my site. When
I have a pagination script, which can be seen here: http://www.automotori6282.tk/phpsandbox/ This is the
Im trying to make a file input field have the following extensions only .zip,
Trying to make a make generic select control that I can dynamically add elements
Trying to make a MySQL-based application support MS SQL, I ran into the following
Trying to make a generic PL/SQL procedure to export data in specific XML format,
Trying to make a web service call to an HTTPS endpoint in my Silverlight
I'm trying to make the case for click-once and smart client development but my
I'm trying to make a data bound column invisible after data binding, because it
I'm trying to make a context menu for a control that is linked to

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.