The stupid question is the question not asked | |
PerlMonks |
Re: last 10 ... next 10?by knobunc (Pilgrim) |
on Mar 28, 2001 at 19:00 UTC ( [id://67831]=note: print w/replies, xml ) | Need Help?? |
If your database does not support LIMIT or an equivalent to allow you to retrieve the appropriate number of rows at an offset then you can do the following:
Below this is a lot of Mason specific blabbering. If you feel like decoding my feverish screed about how I hook the above up to the HTML that the user sees then keep going, otherwise there is probably not much else. Since I am using Mason I wrote a component to handle tables that I pass the parameters for the number of rows to display and the offset to start at and then generate widgets in the html to allow the user to move forward or backward through the dataset generating the correct URL with the appropriate offset and count plugged in. The component is smart enough to know when it has hit the beginning and does not put up a widget to allow you to scroll further backwards, and similarly at the end. To detect the end, it actually cheats, I request one more row than I want and the table component uses that ti detect if there is more data. The table component does not display the additional marker row. In order to allow movement any page that wants to support this has to have 2 page arguments that match the ones that the table component knows how to generate so that it can run the correct subroutine that executes the DB query and pass in the appropriate offset and count parameters. I actually added a further wrinkle by allowing users to click on the column headings in the tables to sort the rows (or reverse sort if they have already sorted by that row). In order to do this I added a third parameter for sorting and the table component generates little up/down arrows to show which column is sorted. The table component then generates link tags for each column heading that tells the page what the appropriate sort is. This then gets passed into the query which validates the sort and turns it into a SQL order by clause. The following is the full blown beast.
In Section
Seekers of Perl Wisdom
|
|