POST/SESSION variables and pagination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Unicron
    New Member
    • Apr 2007
    • 8

    POST/SESSION variables and pagination

    Hi folks, I have been working on a property listing search for a company for a while now and have hit a roadblock. I have searched the net up and down. A lot of Google results lead to this site, but I have never been able to get it to work.

    Here's the setup-

    The user submits search criteria via POST. The results php page pulls the $_POST array and displays the results with pagination of 20 results per page with links for Next/Previous.

    Clicking on the pagination links loses the variables, whether I simply used $_POST or whether I coded, for instance, $_SESSION['county'] = $_POST['county']; at the top of the script. I, of course, am using session_start() ; at the top of the scripts. I have tried all manner of responses regarding sessions,global s,php.ini, and anything else.

    The pagination links uses a query string that refers to PHP_SELF and looks like
    "http://localhost/advancedsearch. php?offset=21"
    where the offset is the 2nd page of 20 results.


    Does anyone have any ideas?
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Clicking on the pagination links loses the variables, whether I simply used $_POST or whether I coded, for instance, $_SESSION['county'] = $_POST['county']; at the top of the script
    Using a hypelink does not generate the POST array .This is only generated from a form. You need to pass the variables as URL variables or as SESSION variables

    Comment

    • Unicron
      New Member
      • Apr 2007
      • 8

      #3
      Thanks for the response! I knew I had to use session variables, but it just wasn't working. Apparently I missed something, because I put this code in and now everything works great-

      foreach($_POST as $k => $v)
      {
      $_SESSION[$k] = $v;
      }

      The strange thing is, I used this before and it didn't work. I must have mucked it up elsewhere. Thanks though! It works.

      Comment

      • Nirav
        New Member
        • Oct 2011
        • 1

        #4
        session_start() ;

        if (! isset session [query])
        {build up query using your post variables;
        assign / set a session[query];
        }

        rest of your code (db connection, pagination, echo results, bla bla)

        Comment

        Working...