Reputation: 719
I'm making a new website to learn coding and am making a results per page for a search application. So basically, I have a select/dropdown that looks like this:
<form name='form1' method='post'>
<font style="font-size:12px;">Results per Page:</font>
<select name='select' onChange='document.form1.submit()'>
<option value='10'<?php if($pagesnum == 10) {echo "selected='selected'";} ?>>10</option>
<option value='15'<?php if($pagesnum == 15) {echo "selected='selected'";} ?>>15</option>
<option value='20'<?php if($pagesnum == 20) {echo "selected='selected'";} ?>>20</option>
<option value='25'<?php if($pagesnum == 25) {echo "selected='selected'";} ?>>25</option>
</select>
</form>
This is just is taking the user's desired number of results per page and once they change the select/dropdown the page is refreshed. Then I store the users results per page data into a variable called $pagesnum or if the results per page isn't set, just set the $pagesnum to 10 like this (it goes at the very top of the page:
if ($_REQUEST['select'] != null){ $pagesnum = $_REQUEST['select'];}else{$pagesnum = 10;}
Then I ,in my pagination, (which I can post if you need it here) makes the total results per page or $totalpages equal to $pagesnum like this:
$total_pages = $pagesnum;
My problem is that I have a Refine Search which suggests related search terms that link to pages like search.php?q=A+Link+That+is+a+different+page and the value of $pagesnum is lost. How do I get what the user sets as $pagesnum and have it set across multiple pages?
Upvotes: 0
Views: 1017
Reputation: 12437
you can think about storing array in session if you have multi select drop down
otherwise just a session variable is enough
http://www.phpriot.com/articles/intro-php-sessions/7
Upvotes: 1
Reputation: 5179
Please have a look at PHP Sessions, here's an example of how you'd apply it in your case.
session_start();
if(!empty($_REQUEST['select'])){
$pagesnum = $_REQUEST['select'];
$_SESSION['pagesnum'] = $pagesnum;
}else{
$pagesnum = $_SESSION['pagesnum'];
}
you can use the code above instead of this
if ($_REQUEST['select'] != null){ $pagesnum = $_REQUEST['select'];}else{$pagesnum = 10;}
Upvotes: 1