如何将变量从一个页面传递到另一个页面?
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.
e.x 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;
我正在创建一个有很多页面的网站。 您可以通过下拉菜单更改每个页面中显示的帖子数量。 我的问题开始,如果我改变帖子的数量移动到下一页它恢复默认。 p>
ex默认帖子显示为30,然后我将其更改为40.当下我 更改页面在下一页再次降至30。 p>
我尝试了类似的东西,但遗憾的是无效。 p>
&lt; form method =“get”name =“SkipPage”&gt;
&lt; select name =“results_no”onChange =“document.forms ['SkipPage']。submit()”&gt; `
&LT;?PHP
....
&GT;
&LT; /选择&GT;
&LT; /形式&GT;
代码> PRE>
$ reults_no = isset($ _ GET ['results_no'])? $ _GET ['results_no']:30; code> p>
div>
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.