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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:47:07+00:00 2026-06-10T05:47:07+00:00

I am working on a website that needs to paginate sql database results. The

  • 0

I am working on a website that needs to paginate sql database results. The idea is like this, a user can click on a submit button with each US state’s code to see all of the comments left by users from that state. For example clicking NY should display all people’s comments from NY and clicking TX should display all of TX and so on. Displaying the results in one big list works but I want to paginate those results now. I am currently using this code located in its own paginate.php file which needs to be re-updated each time a new state is shown:

<?php

...

$rs_result = mysql_query($sql); 
$row = mysql_fetch_row($rs_result); 
$total_records = $row[0]; 
$total_pages = ceil($total_records / 10); 

for ($i=1; $i<=$total_pages; $i++) { 

echo "<a href='?page=".$i."'>".$i."</a> ";

}; 
?>

The code itself doesn’t exactly work because it makes the page refresh. Doing that loses the memory of which state was previously clicked on. How can I change this to work with Ajax so I don’t need to refresh the page. If you need more information let me know.

  • 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-10T05:47:08+00:00Added an answer on June 10, 2026 at 5:47 am

    You need to wrap the results in a DIV that has an assigned ID and change the URL’s to point a javascript function (I would recommend jQuery). The function has to get the data that will be displayed in that div.

    eg:

    <div id="results">
    </div> 
    
    <?php
        for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='?page=".$i."' onclick="getPage('".$i."'); return false;">".$i."</a> ";
        }; 
    ?>
    
    // and script
    
    // the script asks result.php for page and returns html result.
    <script type="text/javascript">
        function getPage(page){
            $("#results").load("result.php", { page: page } );
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a project that involves a database (My SQL), website (PHP) and
I am working on a website that needs access to local resources, like RFID
Working on a website that has Employee and Branch entities, using a database table
I'm working on a website that will use features of social networking (like facebook
I'm working on a website that requires us to log a user out after
I am working on a website that uses a remote websites database to check
I'm currently working on a website that needs a sort of sticky footer, but
I am currently working on a website that users can download binary media files
I'm working on an ASP.NET website that needs to be internationalized. I'm using .resx
I am working on an asp.net website that needs to be section 508 compliant.

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.