[英]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. 显示的默认默认帖子是30,然后我将其更改为40。在我更改页面的那一刻,下一页它再次降至30。
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"];
然后,您可以将var与
$_POST["myHiddenVar"];
But if you want a persistent choice use sessions. 但是,如果您要持久选择,请使用会话。
session_start();
on each page and access/edit your var with $_SESSION['myVar'];
在每个页面上,并使用
$_SESSION['myVar'];
访问/编辑您的var $_SESSION['myVar'];
If you want to make a user choice persistent, the usual solution is to save it in a cookie. 如果要使用户选择持久化,通常的解决方案是将其保存在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. 编辑:或在SESSION中,但我的意思是您不必为用户紧随其后的每个链接将值作为GET参数传递。 You set it once and test if set on each page that need it.
您只需设置一次,然后测试是否需要在每个页面上进行设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.