floridaflatlander Posted December 21, 2011 Share Posted December 21, 2011 The urls on my localhost look like a joke and I hope someone has a solution. I use $_SERVER['QUERY_STRING'] so the first number looks okay, it's that as I go up in page number to 2,3,4,5, etc it starts to look funky. The first time before the 2 for the second page is clicked it looks normal, the second time after the 2 is clicked they look screwy and as you can guess it keeps getting longer each time a number is clicked. I know that each time I go to a new page $_SERVER['QUERY_STRING'] changes and thats the problem. Here is the code I use $qstring= htmlentities($_SERVER['QUERY_STRING']); // Make links to other pages if (($pages > 1) && ($start >= 0)) { // Add space and start a paragraph echo "\n<div id=\"page_num\"><p>"; // Determine what page the script is on $current_page = ($start/$display)+1; //If its not the first page make a previous button if ($current_page !=1) { echo '<a href="subject.php?'.$qstring.'&s=' . ($start-$display) . '&p=' . $pages . '">Previous</a> '; } //Make all the numbered pages for ($i = 1; $i <=$pages; $i++) { if ($i !=$current_page) { echo '<a href="subject.php?'.$qstring.'&s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a>'; } else { echo $i . ''; } } //End for loop // If its not the last page make a next button if ($current_page != $pages) { // $qstring = str_replace("($start + $display)&p=$pages", "", $qstring); echo '<a href="subject.php?'.$qstring.'&s=' . ($start + $display) . '&p=' . $pages. '">Next</a>'; } echo "</p>\n</div><!-- End page numbers div -->\n"; // Close paragraph } // End of "if (($pages > 1) && ($start >= 0))" links Is there a work around to this, a different way of doing it and if or switch or something. thanks Quote Link to comment https://forums.phpfreaks.com/topic/253621-need-solution-to-my-god-awful-urls-for-page-links/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2011 Share Posted December 21, 2011 See the use of http_build_query in this post- http://www.phpfreaks.com/forums/index.php?topic=349554.msg1649534#msg1649534 Quote Link to comment https://forums.phpfreaks.com/topic/253621-need-solution-to-my-god-awful-urls-for-page-links/#findComment-1300184 Share on other sites More sharing options...
floridaflatlander Posted December 21, 2011 Author Share Posted December 21, 2011 Thanks PFMaBiSmAd, I'll check that now. I was just getting ready to post this --------------------------------------------------------------------------------------------------------------------------------------------------- Okay what I've done was I put use my if conditions for the sql and hard coded it like this if ((!$id_sub) && ($state)) { // Select records to display $q = "SELECT ................................... "; $qstring = "cat=$category&id_sub=Null&state=$state; } if ((!$id_sub) && (!$state)) { // This is the ********** MAIN QUERY ********** // Select records to display $q = "SELECT ................................... "; $qstring = "cat=$category"; } Then I insert it into echo '<a href="subject.php?'.$qstring.'&s=' . ($start-$display) . '&p=' . $pages . '">Previous</a> '; Quote Link to comment https://forums.phpfreaks.com/topic/253621-need-solution-to-my-god-awful-urls-for-page-links/#findComment-1300186 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.