Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help maintaining state across pages 2

Status
Not open for further replies.

leegold

Technical User
Mar 19, 2002
39
US
Probably a newbie question about "state":

My problem is I have a search form, so user enters a keyword <enter>, then this form posts to another page were the result are displayed. But this display page uses pagination to break the results up into several subsequent pages. The 1st page is OK, but 2nd...last display pages loose the key word variable I initially posted.

Seems I could keep passing the keyword with GET, I already use
GET to pass pager info. Or I could try a SESSION way. I'd prefer
not to use cookies.

Ques 1.
How do I pass more than one (say two in this case) variables
to a new page with GET. right nowfor the pager I have eg.
echo "<a href=\"search_test2.php?page=$i\">Page $i</a>";
How would I stick $key_word in there to also pass it on to
the next page? Then at the target page I have now:
$page = $_GET['page'];
So do I just add: $key_word = $_GET['keyword'];
Just snippets would help w/syntax.

Ques 2.
I also want to try a SESSION way to maintain state. Again, I have
a building block but not sure of syntax. How do I conbine the two
blocks below so it will work. I want to maintain state of the user's
input keyword. Not sure how combine the html and the php below.
Thanks.


<?php
session_start(); // start session
$_SESSION['keyword'] = 'key_word';
?>

<form action="search_test2.php" method="post">
<p>Your key word: <input type="text" name="key_word" /></p>
<p><input type="submit" /></p>
</form>
 
if its in the query string then:
asd.php?Variabl1=Value1&Variable2=Value2

Known is handfull, Unknown is worldfull
 
In response to question 2...

In the script to which the form submits its data, the superglobal array $_POSST will contain the values from your POST-method form.

Once you have invoked session_start(), all you have to do is something like:

$_SESSION['some_element'] = $_POST['some_field_name'];

All future scripts will be able to access the values.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top