Question

I'm new to post/redirect/get. I'm coding up the first real site that led me to discover the need for PRG. So I had written and gotten working code that did the following:

1) user enters a search string

2) we search the database and find their desired search results

3) if we found their search results successfully, we alter the database -- 
   a 'frequency of lookups' -- to indicate the user searched and found what 
   he was looking for

4) then display the results he searched on

What I found was refreshing the page in the browser resulted in the user seeing his same search results again but we incremented the 'frequency of lookup' -- the user is limited in the frequency of lookup in the database -- so if the user refreshed the page too many times, they ran through their hourly ration of database lookups. That's when I discovered Post/Redirect/Get a few days ago.

I am now going through the site and altering all pages that alter the database and display results and switching them over to PRG. Here is the new process:

1) user enters a search string

2) we search the database and find their desired search results

3) if we found their search results successfully, we alter the database -- 
   a 'frequency of lookups' -- to indicate the user searched and found 
   what he was looking for

4) PRG to a 'results' page

5) then display the results he searched on

And I ran into a problem. I need to somehow 'pass' their search results from step (2) above to the new 'results' page in step (5) that I created to implement PRG.

So my question is -- is there a 'most common' way to do this? In reading around I've seen 'save the results in a .CSV file' and also 'save the database search results in the SESSION.'

I want to save the search results in the SESSION then on my 'GET' page I added for PRG to display the result, I'll read the search results from the session variable and display them.

By that I mean I want to do this:

$result = mysql_query($query, $theDbServer);
$_SESSION['theSearchResults'] = $result.

Then on the 'display' page, read back the search results from $_SESSION['theSearchResults'] and display them using:

 $result = $_SESSION['theSearchResults'];
 $row = mysql_fetch_row($result);

Is this a normal approach? And I suspect I cannot save the raw $result in a session variable like the above -- but I'm also not sure how to put the $result above into the $_SESSION -- how is that normally done?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top