n8w Posted December 24, 2007 Share Posted December 24, 2007 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++; } } Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/ Share on other sites More sharing options...
roopurt18 Posted December 24, 2007 Share Posted December 24, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/#findComment-422310 Share on other sites More sharing options...
predator Posted December 24, 2007 Share Posted December 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/#findComment-422338 Share on other sites More sharing options...
n8w Posted December 28, 2007 Author Share Posted December 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/#findComment-424596 Share on other sites More sharing options...
roopurt18 Posted December 28, 2007 Share Posted December 28, 2007 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; Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/#findComment-424846 Share on other sites More sharing options...
n8w Posted December 30, 2007 Author Share Posted December 30, 2007 hey roopurt18 thanks so much .. that is a great concept .. much cleaner than how I normally do things. Quote Link to comment https://forums.phpfreaks.com/topic/83022-solved-simple-for-you-difficult-for-me/#findComment-425595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.