I have this for navigation, and when I switch to page 2, it will lose the &type= Let's say I select "checked", the first page it shows fine, as it het the whole string, but when I switch pages it loses... here's the code:
// navigation
if($_GET['start'] && is_numeric($_GET['start']))
{
$start=$_GET['start'];
$start=((int)($start/$search_count))*$search_count;
}
else $start=0;
$info['curpage']=ceil(($start+1)/$search_count);
$info['total_pages']=ceil($info['total_results_count']/$search_count);
$navigation=array();
$navigation[]='<span class="navi navi_current"> -'.$info['curpage'].'- </span>'."\n";
$inc=$dec=$start;
$tcnt=0;
for($i=0;$i<9;$i++)
{
$inc+=$search_count;
$incp=ceil(($inc+1)/$search_count);
$dec-=$search_count;
$decp=ceil(($dec+1)/$search_count);
if($inc<$info['total_results_count'])
{
array_push($navigation,'<span class="navi"> <a href="./?q='.$_GET['q'].'&start='.$inc.'"&type='.$_GET['type'].'>'.$incp.'</a> </span> '."\n");
$tcnt++;
}
if($dec>=0)
{
arra开发者_JS百科y_unshift($navigation,'<span class="navi"> <a href="./?q='.$_GET['q'].'&start='.$dec.'">'.$decp.'</a> </span> '."\n");
$tcnt++;
}
if($tcnt>=10) break;
}
$navigation=join("",$navigation);
// end navigation
I've tried adding &type='.$_GET['type']. to the array_unshift, but it doesn't work.. any help will be appreciated! thanks.
It's outside of the quote:
'&start='.$inc.'"&type='.$_GET['type'].'
It should be
'&start='.$inc.'&type='.$_GET['type'].'"
(Notice the placement of the doublequote...
In you code, you have done an error with the HTML-syntax:
<a href="./?q='.$_GET['q'].'&start='.$inc.'"&type='.$_GET['type'].'>
As you can see, the "
is a little bit to early, in front of &type=
when it should have been after. What you really want to do is
<a href="./?q='.$_GET['q'].'&start='.$inc.'&type='.$_GET['type'].'">
If might be easier if you build the URL in advance:
$href = './?q='.urlencode($_GET['q']).'&start='.$inc.'"&type='.urlencode($_GET['type']);
array_push($navigation,'<span class="navi"> <a href="'.htmlspecialchars($href).'">'.$incp.'</a> </span> '."\n");
That makes it easier to apply proper encodings for the two contexts (urlencode
for URL query and htmlspecialchars
HTML attribute value). Or doing this using http_build_query
:
$args = array('q'=>$_GET['q'], 'start'=>$inc, 'type'=>$_GET['type']);
$href = './?'.http_build_query($args, '', '&');
array_push($navigation,'<span class="navi"> <a href="'.$href.'">'.$incp.'</a> </span> '."\n");
精彩评论