r/PHP•
puttyguy

Doing away with pagination links in favor of end-of-page scroll dynamic loading of items.

I need some ideas on how best to approach loading items dynamically.

The pagination currently just uses a query string &limit=12 and goes up by 12 each time you click the page links 1,2,3 etc... The front-end dev wants refactor the views of this catalog page to use something like knockout.js.

I was thinking maybe just send him like the id of the last item that was loaded (the ids are correctly stored sequentially in the DB) and then his ajax request can return that id so my logic can offset + 1 and retrieve the next set of 12 items.

I don't know, maybe I'm over thinking this?

Posted Jun 18, 2014, 3:33 PM UTC

18
Cookizza•

That's exactly how it's done, the front end communicates the offset to a generic API method that returns data starting from that offset. No over-thinking required ;)

3
puttyguyOP•

That seems to work as intended.

I'm working on some simple search functionality and this MySQL is way to big to be searching on and sending back json crap, slow as balls. 1 table | 40k+ rows | 80 fields per row.

This question may be better asked in a new thread, but would it be beneficial just to create another field in the table and store the data as json in that field? Then I could potentially drop all the fields that don't need to be searched on, right? It would reduce it to like 15-20 fields per row.

0
robotparts•

Your table sounds improperly designed.

Normalize it a bit and you will probably see some performance improvements.

MySQL/Postgres/etc are all capable of millions of rows on modest hardware if the database is designed properly.

https://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/

4
Kussie•

Your classifying a database with 40k rows as big? From the sounds of it your database has issues, I'd be checking to make sure it's indexed properly.

However with that said your idea is pretty much exactly how endless scrolling works :)

Personally for me though i hate endless scrolling, i much prefer pagination because as a user it let's me jump ahead as far as a i want, where as with endless scrolling, i have to scroll continuously. Thats my personal opinion though

1
alexanderpas•

Not to mention back button breakage on endless scrolling.

2
puttyguyOP•

Kind of, something is fucked up with it. I got my hands on a copy from the admin and it's a little over 2 GB. I was expecting maybe 300 MB tops. Need to figure out what else is being done on this DB.

Any experience importing a 2.1 Gb file to MySQL? Or point me in the right direction? Keep running into server limits.

1
ellisgl•

Side note: Forever scrolling can present some issues with memory usage for end users. I haven't seen this done yet, but if you can remove previous 'divs' while you are scrolling down and add them back when scrolling up (reverse forever scroll), that should help.

1
ScuzzyAyanami•

I do like the infinite scroll concept, but I never see them done with updates to the URL that would allow the user to refresh the page and return to that offset easily. (history.pushState/replaceState() may introduce too many back/forward states mind you)

1