0

I'm working in a online shop, the idea is to list my products in groups of 10 and then navigate through each group.

The question is: It is better to load them all from DB in SESSION variable, or is better to load them from DB 10 by 10 while the navigation

thank you in advance

chino
  • 17
  • 6
  • load from the db when needed. Don't abuse the SESSION variable. –  Aug 19 '15 at 11:40
  • certainly the second option. Session is not ment for huge data, and user many only ever be interested in the 1st product, not the 983rd one, so why load it at all – Steve Aug 19 '15 at 11:40
  • Storing large amount of data in `SESSION` would be bad idea. Fetching them while with limits will be good. – Sougata Bose Aug 19 '15 at 11:41
  • Load it all, store it on run-time and deal with data pagination at the front-end. – al'ein Aug 19 '15 at 11:43
  • I disagree with the comments above. If you've only got a modest data set, consider loading it all at once. Then you can do fun things like this...http://isotope.metafizzy.co/. Also look at concepts like google's infinite scroll widget (like you see when you search for images) – Strawberry Aug 19 '15 at 11:52

2 Answers2

2

You can fetch records from database as and when needed.Suppose you want to display 10 records per page ,then use query

select [* OR field_names] from table_name LIMIT 0,10

In php , You can keep track of record count in some variable and use that in your mysql query.

But,don't get all records at once from database.

Aman Kaur
  • 311
  • 1
  • 7
0

In my opinion you should only load what you need.

If you're only displaying 10 at time, load 10, assuming MySQL use LIMIT and OFFSET to do this.

MySQL Data - Best way to implement paging?

If you load them all and store them in a $_SESSION variable, you're loading 10 + x amount of products which increases page load time, to display 10 products and also unnecessarily saving them in a $_SESSION.

Community
  • 1
  • 1
JohnnyFaldo
  • 4,121
  • 4
  • 19
  • 29