On Wed, 12 Jun 2002, Vuillemot, Ward W wrote:

> Date: Wed, 12 Jun 2002 06:58:24 -0700
> From: "Vuillemot, Ward W" <[EMAIL PROTECTED]>
> To: 'Peter Bi' <[EMAIL PROTECTED]>, [EMAIL PROTECTED],
>      Eric Frazier <[EMAIL PROTECTED]>
> Subject: mod_perl/passing session information (MVC related, maybe...)
>
> I was wondering how people are saving state between "pages" of a session.
>
> There is a Apache::Session which is sufficient to check to see if
> they are logged in, et cetera.  But I want to be able to remember
> the last query so that I can return results into multple pages along
> with memory of where in the stack I am at.  The easiest would to be
> store the query parameters along with the count information. . .but
> I do not want to use Apache::Session as I believe that has too much
> overhead for this sort of thing.  There are persistent modules, but
> I am wondering if there is a better way with Apache and mod_perl --
> that ppl have tried and can vouche for its validity.
>
> Thanks!
> Ward

Ward,

I do things like this all the time, though I wonder if I don't do it
the Hard Way.  Basically, I define a MAX_RESULTS per page (like 25)
and return the first set of records to the user.  To make the
clickable links to "Previous," "Next," and the 1-n pages, I've munged
the query results in Perl and a couple template packages to make each
link contain everything necessary to perform the query again
(including every parameter from the original request) and putting in
the appropriate "limit_start" number (or whatever you want to call
your limiting variable) for the set.

E.g., if I'm looking for all the records where name="foo" and
size="M" and I got back 100 results, with a MAX_RESULTS of 25, I'd
have to make four pages.  The second page might look like this:

    <a href="/search?name=foo;size=M;limit_start=0">Previous</a> |
    <a href="/search?name=foo;size=M;limit_start=0">1</a> |
    2 |
    <a href="/search?name=foo;size=M;limit_start=50">3</a> |
    <a href="/search?name=foo;size=M;limit_start=75">4</a> |
    <a href="/search?name=foo;size=M;limit_start=50">Next</a>

Now, that's a lot of stuff to make sure is in your output, and adding
or changing a parameter means a lot of fixing.  However, it is fairly
simple, and I can grok it, so I stick with it.  I'd be happy to hear
of better ways.

FWIW, I do pretty much the same thing to re-sort tables of data by
column headers.  So for a table of shirts with attributes of "color"
and "price," I'd do something like:

FWIW, I do pretty much the same thing to re-sort tables of data by
column headers.  So for a table of shirts with attributes of "color"
and "price," I'd do something like:

    <tr>
        ...
        <th><a href="/view_shirts?order_by=color">Color</a></th>
        <th><a href="/view_shirts?order_by=price">Price</a></th>
        ...
    </tr>

Sprinkle in the same code for limiting to a managable result set, and
those are all my tricks.

HTH,

ky

Reply via email to