Jump to content

[SOLVED] simple for you .. difficult for me


n8w

Recommended Posts

okay .. I am doing pagination .. but I am adding a &page=$current_page to the query string so I am getting urls that keep adding more and more pages

 

http://www.illustrationmundo.com/audio_index.php?&page=1&page=2&page=3

 

How can I change my code so it just replaces the page vs. adding it?

 

Thanks a ton

 

$q=$_SERVER['QUERY_STRING'];
$q =str_replace(array('&', '&'), array('&', '&'),$q);

$counter = 1;
while ($counter <= $num_pages) {
?>
    <? if(($counter-1)==$page ){?>
(<?= $counter ?>) | 
    <? }else {?>
<a href="http://www.illustrationmundo.com/articles_index.php?<?= $q ?>&page=<?= $counter-1 ?>"> <?= $counter ?></a> | 
    <? }?>
    <?

$counter++;
}
}

 

 

Link to comment
Share on other sites

just a quick note if you are keeping the link

 

http://www.illustrationmundo.com/audio_index.php?&page=1&page=2&page=3

 

that will not work it should be

 

http://www.illustrationmundo.com/audio_index.php?page=1&page=2&page=3

 

the first $_GET value is just put after the question mark. However all URL passed information after that is "added" to the list with the use of &

 

for example

 

www.domain.com/index.php?test=1&test=2

Link to comment
Share on other sites

You're capturing the current query string in $q and adding it to the URL, as well as adding &page=$current_page.

 

So if $q already has page in it you'll just be adding it again, make sense?

 

Hey thanks for replying

 

.. yes that does make sense .. but I don't know how to fix it because I need the query string for the other parameters .. but I need to replace the page variable with then new one ...

 

how would you recomment doing that .. say I have the query string ..but I need to tell it .. its now page 7

 

thanks

Link to comment
Share on other sites

You could just rebuild it from all the $_GET values:

 

$newQueryString = Array();
foreach($_GET as $key => $val){
  if($key == 'page'){
    $val = $newPage;
  }
  $newQueryString[] = $key . '=' . $val;
}
$newQueryString = implode('&', $newQueryString);
echo $newQueryString;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.