Pergunta

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;

Foi útil?

Solução

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'];

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top