0

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)
    {
        array_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.

2
  • "I have code of mine, please debug it for me" is not a question everyone dream of Aug 8, 2010 at 15:00
  • I'm learning php, i'm not asking to you to fix it, I wanna know what's wrong.. thanks
    – raFF
    Aug 8, 2010 at 15:01

3 Answers 3

1

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...

0
0

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'].'">
0
0

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, '', '&amp;');
array_push($navigation,'<span class="navi"> <a href="'.$href.'">'.$incp.'</a> </span> '."\n");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.