Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
Row Counts / Paging
25/06/2009
18:05
Avatar
jkarlen
Member
Members
Forum Posts: 7
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

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?

26/06/2009
03:05
Avatar
tomcmok
Member
Members
Forum Posts: 10
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

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

26/06/2009
08:00
Avatar
jkarlen
Member
Members
Forum Posts: 7
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

I ended up doing what I hinted at above.  I do my query as normal, load it into an array and only return the portion of the array requested by the rows per page from the jqGrid request.

So far it loads incredibly quickly and still gives me access to the full record count.

26/06/2009
10:03
Avatar
tomcmok
Member
Members
Forum Posts: 10
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

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.

27/06/2009
12:10
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

30/06/2009
11:37
Avatar
tomcmok
Member
Members
Forum Posts: 10
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

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

02/07/2009
02:55
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

02/07/2009
04:53
Avatar
tomcmok
Member
Members
Forum Posts: 10
Member Since:
25/06/2009
sp_UserOfflineSmall Offline

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

02/07/2009
05:19
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Sofia

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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information