Hi,

I have a search form on my page, which feeds into an SQL select statement being built when the user hits the button.

The action page builds the SQL, and displays the 1st 10 entries. When I set up my 'Next' button, I thought I would just call 'PHP_SELF', passing through the row number to start at, so the Select statement would still exist.

However, when the page reloads, the variable which held the select statement gets reset... I found that I couldn't use $_POST['variable'] to get it from the previous form, either...

Is there a way of keeping the variables, other than using Sessions? Can it be done by declaring it a global variable, and if so, are there security issues?

Anyone understanding my problem? 😕 Anyone got any help for me?! Thanks a million!

    Every time you post, your script is executed from scratch. You'll have to give it information all over again.

    These are a few options:

    1) Post the search-query again.
    That way you have enough information to do the query again, with a different LIMIT part. (I assume you used a LIMIT.)

    2) Store the search-query in a session.
    A session is a way to store information on the server. When your script executes again, it retrieves the information you stored in the session from a temporary file. See the manual for details on sessions.

    3) If you build in a session, there's another option: Store the complete result of the query in the session. That way you kind of cache the search, you do not need to ask the database over and over again, and you can sort on a different field. Needs some experience with arrays though.

      I didn't use a LIMIT, as that would only ever bring me back the first 10 (or whatever) results... how would you get to the 2nd 10?

      I wanted to avoid using SESSIONS, mainly because a user sometimes will already have one ste (if they are a member), and sometimes won't (if they are just browsing). But I like the idea of caching the entire result, and using that.

      Is it possible, then, to set the $_POST variables so that they can be got from the next page without using a form? check out the newbie

      Thanks for your ideas....

        I didn't use a LIMIT, as that would only ever bring me back the first 10 (or whatever) results... how would you get to the 2nd 10?

        LIMIT 10 is the same as LIMIT 0,10
        so:
        LIMIT 10,10
        LIMIT 20,10

        I wanted to avoid using SESSIONS, mainly because a user sometimes will already have one ste (if they are a member), and sometimes won't (if they are just browsing). But I like the idea of caching the entire result, and using that.

        Why not? If some are member and some are not, why not use the session to remember if they're logged in or not?

        Is it possible, then, to set the $_POST variables so that they can be got from the next page without using a form? check out the newbie

        Ehmz.... Why exactly?
        If it is cosmatic because you'd rather use a hyperlink just place it in the GET... scriptname.php?varname=value&anothervar=more

        If you mean it's instead of a session or something: No, the server forgot everything it did.

          Excellent, thanks for your help. To be honest, I am used to Oracle 8 RDB, and assumed that the LIMIT would work in the same way, so I will look into using that now.

          Also have thought that I will use a session - with one access control script included in the pages which you need to be logged into, and a different access control script (which doesn't check the DB for passwords etc) for the non-login pages.

          Anyway, cheers for your help.🙂

            Write a Reply...