简体   繁体   中英

How can i pass a variable from one page to another?

I am creating a website, that has many pages. You can change the number of posts shown in each page through a drop down menu. My problem starts if i change the amount of posts move to the next page it comes back to default.

ex default posts shown is 30, and then i change it to 40. The moment i change page it comes down to 30 again on the next page.

I have tried something like that but unfortunately doesn't work.

<form method="get" name="SkipPage">
<select name="results_no" onChange="document.forms['SkipPage'].submit()"> `
<?php
....
?>
</select>
</form>

$reults_no = isset($_GET['results_no']) ? $_GET['results_no'] : 30;

try to use hidden intput

<input type="hidden" name="myHiddenVar" value="<?php echo $myVar ?>"

Then you can use your var with $_POST["myHiddenVar"];

But if you want a persistent choice use sessions. session_start(); on each page and access/edit your var with $_SESSION['myVar'];

If you want to make a user choice persistent, the usual solution is to save it in a cookie.

EDIT: or in SESSION but my point is that you don't have to pass the value as a GET parameter for each link followed by the user. You set it once and test if set on each page that need it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM