Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: web counter, next-page method?

From: maarten:vrijheid at: 7-Apr-2004 10:38

> I will soon prepare some part of portal. Let's suppose I get data from > db, I have template system, where I simply put data into table or > whatever xhtml structure. Now what I am not sure about how to do is - > e.g. my table will have 30 rows, db query returns 150 rows, so I need to > introduce some next-page continuation mechanism. Any suggestions? That > is not about search & replace only. xtml template is designed by our gfx > designer, cgi/data part is mine responsibility. We just set yesterday > and our designer asked, what should he put into xhtml template? And now > I am not sure how to do it. Maybe it could use similar aproach as when > you construct gfx based counter? Dunno. Any suggestions, examples?
Here is what you should do, how you do it is just a matter of your own preferences. Not so much code, but a design. When your data is returned, you chop the first n entries of, where n is the number of rows you want to display. You will also have an offset o, initially zero and growing with n on each page. Now you'll also need a way to make the query "persistent" over multiple pages. You could do this using some session mechanism, where you link the session-id to a query-id and the query is stored. Or you could bluntly encode the query using simple symmetric encoding with blowfish, or easier, the core-based functions 'encloak and 'decloak. So we have right now references to: the query, the offset (basically the starting row) and how many rows to come. Now: the CGI function that executes the query takes two extra parameters, the offset and the number of rows to return. You can use SQL or REBOL to use those two values. I'd start with REBOL, doing an 'at and 'copy/part on the returned series, and if that works start optimizing the SQL. Your "Next" button / image / link simply is a GET/POST to the query supplying the offset and number of rows. The same for a previous button, but then backwards. --Maarten