Forum


18:05

25/06/2009

What is the best way to handle row counts in conjunction with paging? If the SQL statement that generates the data has a limit statement on it then your number of rows will always be the limit or less.
It seems painful to run the query once, probably with just a count(*), just to get the whole universe and then run it again with the limit.
Would it be more efficient to run the query and filter $num_rows into a seperate array?
03:05

25/06/2009

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
cheers, Tom
10:03

25/06/2009

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).
T.
12:10

Moderators
30/10/2007

Hello,
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.
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
02:55

Moderators
30/10/2007

Hello,
Just for information - how do you check that there are more records - do you use SQL command for this purpose?
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
04:53

25/06/2009

Tony,
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.
Cheers,
Tom
05:19

Moderators
30/10/2007

Hello,
I like the simples solutions too 🙂
Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
139 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66