hi, see my similar topic here I was hoping to get some hints from the author. Obviously counting records just to get the paging to work is not efficient – I've suggested a sort of workaround that could solve the problem, without changing the js grid code
What if you have complex SQL statement that joins several tables which itself takes time and a result gives you 100 thousands records. You will have to fetch them all just to count them and it will take quite some time and you will end up with displaying just ten. The difference in time may be couple of seconds wasted just to load into an array (not speaking about the unnecessary memory consumption).
How should know the grid that there are more records for the next page, supposing that these records are in the database?
So the simple solution is:
Disable the record view, page input and total pages view, then server side return a relative big number for total pages without to query the database for such information.
Well, instead returning the big total number of pages (what is the relativr big number? that depends on the databese you deal with). My solution is to check if there are more records and if so just return the information that there is ONE more page. this way the paging and page input work well
If there's a request for 10 rows I'm trying to fetch 11 (one more) by iterating throught the resultset (I have to do that anyway to build the XML/JSON). If there is at least one more row – it means there are more data and at this point it doesnt matter how many – this information is just required to let the paging display the “Next” icon
I'm not sure how that solution would work in PHP, but I have my backend app server done in Delphi and there is a component that let's me iterate through the resultset and it informs me if there are no more rows to fetch.
I suppose that in PHP if you ask for 11 rows and load the resultset into an array, you can heck the real array length afterwards.
Smart and simple – isn't it 😉
The whole point is to keep in mind that the less SQL statements and the less fetches the better. Especially if you work on the databases with hundreds of tables containing hundred thousands of records or even more.