MySql pagination dynamic data

Hi folks could you help me please with this one.

Let say I got 100 users online and Id like to show them all on the page with the limit of 20 per page.

Now the query would be ordering those users by the timestamp asc.

The problem Im facing is what if by the time I get to page 5 last users have become first ones case their timestamp is the most recent one. That would mean i would not get show them at all.

How does pagination work with the dynamic data.

By pagination I mean Jquery show more ajax data output.

Well, when do you want to refresh the data?

If you want the data to be “live”, then going to page 5 and not seeing the people who have moved to page 1 is correct behavior.
If you want a snapshot of the data at the moment the person loads the page, pull all the data at once (don’t limit your query) and use Javascript to hold the data in memory and display it page-wise.

Thanks so much please bear with me buddy. I just started experiencing with dynanic data load and I gotta say i am terrible with JavaScript and jquery.

OnLoad with the help if ajax I am fetching first 20 results and returning html.

In order to convert data into var do I have to also return a json containing all userIDS along with html?

Then on show more click grab next 20 ids pass them to controller format and return html?

Each html will have a unique id like last user id of the cached data. Then to load next batch simply select 20 after that id.

select all data.
store data as an array variable.
When you change page, instead of sending another ajax request, slice the array and hand the correct slice to your control code.

Amazing.

Im gonna limit query to 500 which is the maximum results I allow across the site.

Then create an array that will store: profileURL, displayName, avatar, and about me section substr to 100 chars.

Should I HTML format that data with javascript or store it already formatted inside the array?

up to you, though I wouldnt recommend it if the logic’s going to be the same for every record. If your client never clicks on page 5, then the time you waste formatting the rows for page 5 could have been better off not used, right?

If the query limit is only 500 then perhaps try showing a link to each and use Ajax to display the clicked user link:

(https://www.johns-jokes.com/all-the-jokes)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.