Forum Moderators: coopster
<input type="checkbox" name="jornals[]" value="1">
<input type="checkbox" name="jornals[]" value="2">
The method of the form is GET.
In first page it is cool, but for second page for third the url is cumulative.See the code:
-----------------------------------------------
if(!isset($page) OR $page=="1"){
$page=1;
$next_page=$page+1;
$link_next=''.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&page='.$next_page.'';
} else {
$prev_page=$page-1;
$link_prev=''.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&page='.$prev_page.'';
$next_page=$page+1;
$link_next=''.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'].'&page='.$next_page.'';
}
}
The link in the first page:
search.php?jornals%5B%5D=1&jornals%5B%5D=2&page=2
And second for third
search.php?jornals%5B%5D=1&jornals%5B%5D=2&page=2&page=3
(CORRECT: search.php?jornals%5B%5D=1&jornals%5B%5D=2&page=3)
Any other PHP Variable works?
I ended up looping through
argv and NOT writing the old parameter, in a similar situation: $qstring=""; foreach($argv as $val) { if (eregi("page=",$val)) { continue; } $qstring .= $val."&"; #$qstring ends up with an & at the end } $link_next=''.$_SERVER['PHP_SELF'].'?'.$qstring.'page='.$next_page.''; $link_prev=''.$_SERVER['PHP_SELF'].'?'.$qstring.'page='.$prev_page.''; Hope that helps!
For your case you can use it like
$link_prev='page='.$prev_page.getQueryString("page","&");
It will automatically add & after page=1 and then rest of parameters
example
start page=1&a=0&b=3
after this function
page=n&a=0&b=3
where n is your new page number.
<?
function getQueryString($notThis="=",$preString)
{
//set default query string as pre string
$qStr=$preString;
$arr_notThis=explode(",",$notThis);
//go through each url parameter
$qStrings=split("&",$_SERVER['QUERY_STRING']);
foreach ($qStrings as $qString)
{
$key_val=split("=",$qString);
$found=false;
foreach($arr_notThis as $val1 => $val2){
if (strcmp($key_val[0],$val2)==0) $found=true;
}
// if the parameter key is NOT compared with "notwanted", add it into new string
if (!$found && isset($key_val[0]) && isset($key_val[1]))
$qStr.= $key_val[0]."=".$key_val[1]."&";
}
//chop off last & if length is greater than zero
$len=strlen($qStr);
if($len>0) $qStr=substr($qStr,0,$len-5);
//return the new created string
return $qStr;
}?>