0

I have complicated MySQL query that responses large amount of data, as a result the PHP page that shows this response got pending status (DevTools) as long as 2-3 minutes of running time, before the page fully loaded and I've been able to see the contents, meanwhile waiting its a blank page...

Is there an elegant way to maybe slice the result generation like each row will be echo'ed to the page before php script going to the next row (while loop). May be a jQuery asynchronous request or some other clever and elegant solution.

So finally I'll be able to start seeing the results as page loads, it may take the same 2-3 minutes of loading but each second (for example) I'll see one more row echoed to the page, instead of waiting 2-3 minutes in front of blank page.

P.S. I think it should work like some images lazy loading or like facebook scroll down that loads next results (but without the scroll)

Community
  • 1
  • 1
IncreMan
  • 356
  • 3
  • 10
  • Instead, let's try to optimize the slow SQL statement. Please provide `EXPLAIN SELECT ...` and `SHOW CREATE TABLE`. – Rick James Apr 23 '17 at 18:23

1 Answers1

2

you can use limit clause in mysql query after each five second you can run your code and get next 10 rows on your page using ajax.

Amit Gaud
  • 756
  • 6
  • 15
  • 1
    the above solutions seems good because you need to use pagination because of huge data and need to create required column indexing - so data can be retrieved faster. in the above suggestion seems good but Instead of triggering for every 5 seconds. you can implement scrollable pagination Ref here: https://www.thesoftwareguy.in/ajax-scroll-pagination-php-mysql/ Because if user is not interested in much more data, than no need of retrieving and keeping it in the page. Use loader images,so user will be awaware data is still retrieving. – Senthil Apr 23 '17 at 15:56
  • @Senthil I'll take a look at the link you provided, but actually i need that all data to be loaded into one page and started loading onload (not on scroll), because finally the user should be able to see all data on single page, but he/she will start to work with data that loaded at the beginning instead of pending for 2-3 minutes. – IncreMan Apr 24 '17 at 10:43