I wonder if anyone can help. I'm looking for some efficient/well thought through/language independant/whatever else you want to call it solution for the following problem:
I'm writing a web application for a client. Part of it is a search screen - search for records from the database based on some user provided criteria.
No, problem, 'tis written, and works fine.
Now the client is asking if I can add a 'paging' facility - where the user can select how many records per page are shown, with the usual Next/Previous links. Standard stuff. In addition, the page should show "Showing records x thru y of z"
The objective is two-fold:
1) make the returned list shorter and more managable for the user
2) reduce un-necessary network traffic / database load / application load (without paging, the result set could run into many thousands, and the user more than likely only wants something from the last 100)
I've written a solution that works, but I'm not that happy with it, and wanted some other opinions to ensure that it is reasonably sound.
What I've written basically does 2 queries per page hit - the first query does a SELECT COUNT(*) .... with the user entered criteria to get the total number of records (so I can display "Showing records x thru y of z")
Then I do the same query again, but specifying the fields I want instead of COUNT(*), and applying "WHERE ROWNUM < value and ROWNUM > value" clauses. I manage the upper and lower extents for the ROWNUM clauses as hidden fields. When the user clicks Next or Previous, the page reloads and the whole lot happens again but with the new upper and lower extents.
As I said, it works fine, but I need to ensure its a good solution. Bearing in mind one of the objectives is to reduce network and database traffic, 2 queries cant be a good idea ??
So I thought, OK, I'll only do one query without specifying the ROWNUM clauses (so I get all records), and manage the paging internally. I can put the entire record set into a data structure like an array (and thus get the total records), and then store the array in the session. Display the first n rows, then when the user clicks next, the page reloads, does not do the query as the session state already has the array, and just display the next n elements.
I dont like this as the database will always return the full set of records (many thousands), but chances are for the most part the user will only want to see the first page - I will have retrieved 1000's of records, only to have displayed the first 100.
Or, do it without page reloads; display the result set as a DHTML table, only displaying the number of records required. When the user clicks next the DHTML table is updated with client side JS.
Again, I dont like this for the same reason above; plus I will need to maintain a very large JS array, and write a load of carthorse client side JS to update the results table.
Anyone got any bright solutions for this ?
Cheers
Nathan
I'm writing a web application for a client. Part of it is a search screen - search for records from the database based on some user provided criteria.
No, problem, 'tis written, and works fine.
Now the client is asking if I can add a 'paging' facility - where the user can select how many records per page are shown, with the usual Next/Previous links. Standard stuff. In addition, the page should show "Showing records x thru y of z"
The objective is two-fold:
1) make the returned list shorter and more managable for the user
2) reduce un-necessary network traffic / database load / application load (without paging, the result set could run into many thousands, and the user more than likely only wants something from the last 100)
I've written a solution that works, but I'm not that happy with it, and wanted some other opinions to ensure that it is reasonably sound.
What I've written basically does 2 queries per page hit - the first query does a SELECT COUNT(*) .... with the user entered criteria to get the total number of records (so I can display "Showing records x thru y of z")
Then I do the same query again, but specifying the fields I want instead of COUNT(*), and applying "WHERE ROWNUM < value and ROWNUM > value" clauses. I manage the upper and lower extents for the ROWNUM clauses as hidden fields. When the user clicks Next or Previous, the page reloads and the whole lot happens again but with the new upper and lower extents.
As I said, it works fine, but I need to ensure its a good solution. Bearing in mind one of the objectives is to reduce network and database traffic, 2 queries cant be a good idea ??
So I thought, OK, I'll only do one query without specifying the ROWNUM clauses (so I get all records), and manage the paging internally. I can put the entire record set into a data structure like an array (and thus get the total records), and then store the array in the session. Display the first n rows, then when the user clicks next, the page reloads, does not do the query as the session state already has the array, and just display the next n elements.
I dont like this as the database will always return the full set of records (many thousands), but chances are for the most part the user will only want to see the first page - I will have retrieved 1000's of records, only to have displayed the first 100.
Or, do it without page reloads; display the result set as a DHTML table, only displaying the number of records required. When the user clicks next the DHTML table is updated with client side JS.
Again, I dont like this for the same reason above; plus I will need to maintain a very large JS array, and write a load of carthorse client side JS to update the results table.
Anyone got any bright solutions for this ?
Cheers
Nathan


Comment