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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:30:01+00:00 2026-06-08T20:30:01+00:00

I don’t have much experience with Javascript, Node.js or Socket.io. I’m trying to create

  • 0

I don’t have much experience with Javascript, Node.js or Socket.io. I’m trying to create an app with a jQuery pagination plugin, http://beneverard.github.com/jqPagination/, that queries a mysql database (with keywords that the user enters into a textbox), gets the total number of results back along with the first 15 results for the first page (using LIMIT) then uses the total number of results to determine how many pages will be needed.

Here is the code snippet (client-side javascript for setting the maximum number of pages for pagination) that I can’t get to work:

var maxpagenumber;

socket.on('resultsnumber', function(count)
{
    maxpagenumber = ~ ~(this.count / 15) + 1;
});

$('.pagination').jqPagination({
    max_page: maxpagenumber,
    paged: function(page)
    {
        ...
    }
});

I looked at the variable maxpagenumber in Chrome and noticed that it is undefined. The query for the first 15 results works it’s just that the pagination only shows one maximum page.

As I was looking around online for help I found a question on accessing a variable outside an asynchronous callback function: Using variable outside of ajax callback function. I used the idea from the marked answer and applied it to my code:

var setPagination = function(maxpagenum)
{
    $('.pagination').jqPagination({
        max_page: maxpagenum,
        paged: function(page)
        {
            ...
        }
    });
}

socket.on('databasenumber', function(count)
{
    var maxpagenumber = ~ ~(this.count / 15) + 1;
    setPagination(maxpagenumber);
});

This gives the same result as the previous code snippet. The only working option I have so far is this:

socket.on('databasenumber', function(count)
{
    var maxpagenumber = ~ ~(this.count / 15) + 1;
    $('.pagination').jqPagination({
        max_page: maxpagenumber,
        paged: function(page)
        {
            ...
        }
    });
});

This works perfectly until the user enters new keywords into a textbox to search again. Once the user does a second search many bugs arise. Anyone have any ideas on how to make this work? Should I show more code to explain my problem? Maybe I’m just not understanding this snippet of Javascript properly? Any help or advise would be much appreciated.

  • 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-08T20:30:03+00:00Added an answer on June 8, 2026 at 8:30 pm

    The problem seems to be that you’re only setting the maxpagenumber once. You really need to set that each time your dataset changes. I think some combination of your second set reworked will be best, but I’m not 100% familiar with the jqPagination control, so that is probably where things aren’t working out. You may need to feed it a new maxPageNum via some API call?

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

Sidebar

Related Questions

I don't have any experience in updating a Rails app and when I google
I don't have much PHP experience and I want to know how to best
Don't have much to say, just can get into the event handler. XAML: <Grid>
I don't have much knowledge about the IPv6 protocol, so sorry if the question
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't know how to explain it better but i'm trying to get a response
Don't they both have to convert to machine code at some point to execute
Don't overthink this - there's a very commonly used term and I ... have
Don't think my virtualhost is working correctly. This is what I have inside of

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.