I have a rather large table that takes about 10-20 seconds to fetch depending on the query. That makes website seems slower due to that.
I was thinking of using LIMIT to limit the number of results and using ajax to display the whole table bit by bit.
Right now I am using ajax to display the whole table at once.
I am thinking of doing something like this…
Backend:
$offset = 0;
$rowsToFetch = 100;
{
//Loop
$query = "SELECT * FROM TABLE_NAME LIMIT $offset, $rowsToFetch"
$offset = +100;
$rowsToFetch = +100;
}
Frontend:
Call ajax function that will call the back end part recursively and display part by part until finished.
I am sure it’s a bit more complicated than that.
Is there a better way to do this? Any ideas how to start? Pitfalls to lookout for?
P.S. I don’t want to use pagination. I want to display everything in one page(Benefits: CTRL+F)
Edit: Fetching in the database(command line) takes about 5-7 seconds. But in the website displaying the records take about 10-20 secs. Query takes about 4-5 secs. I timed individual sections of the page to identify that.
That won’t speed up the query itself, because the first thing done by mysql is implementing the whole query, and after that it just takes the needed number of results. Consider using nidexes instead or eliminate join number, try sevaral simple queries.