Murdock Posted February 5, 2008 Share Posted February 5, 2008 Hi All. I have a small problem I am hoping someone may be able to shed a little light on. I have a pagination script that works perfectly... for the most part. Everything works as expected when navigating through a main category page. The pagination links are output via: $this->return .= ($i == $this->current_page) ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[php_SELF]?$this->querystring&page=$i\">$i</a> "; The link(s) produced look like: catalog.php?products=shirts&page=5 However, when throwing a sub-category in to the mix to further refine the results the pagination links are incorrect/broken. It should produce a link like: catalog.php?products=shirts&size=small&page=5 but instead I get: catalog.php?products=shirtssize=small&page=5 Note the missing &. I have narrowed the problem down to how the var $querystring is called in to the pagination class which is: if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page") $this->querystring .= $arg; } } if($_POST) { foreach($_POST as $key=>$val) { if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val"; } } That being said, my PHP skills are "laughable" at best so i'm not sure how to make this work for my needs. If more code is needed I can post it all but I believe (hope) that my problem is really only caused by the above code. Many thanks for your thoughts and time. Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/ Share on other sites More sharing options...
pdkv2 Posted February 5, 2008 Share Posted February 5, 2008 in your code above you probably are missing the "&" see the red line below if($_GET) { $args = explode("&",$_SERVER['QUERY_STRING']); foreach($args as $arg) { $keyval = explode("=",$arg); if($keyval[0] != "page") $this->querystring .= ."&".$arg; } } Cheers ! Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-458611 Share on other sites More sharing options...
Murdock Posted February 5, 2008 Author Share Posted February 5, 2008 Thank you pdkv2! I am very, very close to having this resolved now. Adding the above & worked perfectly for adding the missing character between the category and subcategory and it produces this: catalog.php?products=shirts&size=small&page=1 I have one more small problem though. When navigating through the pages each page clicked through adds an additional & to the beginning of the query_string (which I wrongfully assumed would have been removed automatically) so now it's producing this: catalog.php?&&&&&&&products=shirts&size=small&page=8 catalog.php?&&&&&&&&products=shirts&size=small&page=9 Any thoughts? Thank you again for your time, it's much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-458677 Share on other sites More sharing options...
Murdock Posted February 5, 2008 Author Share Posted February 5, 2008 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459176 Share on other sites More sharing options...
laffin Posted February 5, 2008 Share Posted February 5, 2008 leave the variables ya want in an array, such like $_GET. $args=$_GET; as yer code modifies the the the parameters in processing $if(!isset($args['page'])) $args['page']=1; //page not set, set to page 1 Once processing all done, we want to rebuild the query. first we seperate our key names into a new array. also doing the values, so the key index is the same $akeys=array_keys($args); $avals=$array_values($args); now we implode the keys with the values, with = in between and use urlencode for any special processing. also want to clear out the old args array, as it's no longer needed. unset($args) foreach($akeys as $key = $val) $args[$key]="$val=" . urlencode($avals[$key]); now ya have key=val pairs now to add the & in between $args=implode('&',$args); Now the hard work is done u build yer url string. $url = "http://my.site.com/browse.php?$args"; notice we add the '?' manually and ya all set Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459197 Share on other sites More sharing options...
Murdock Posted February 6, 2008 Author Share Posted February 6, 2008 Thank you laffin! With the code you provided I was able to get it resolved and working as expected. If you'd like PM me your PayPal address so I can buy you a coffee. Thank you again, I appreciate it! Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459469 Share on other sites More sharing options...
Murdock Posted February 6, 2008 Author Share Posted February 6, 2008 Oops! I tried to edit my last post but the time limit expired. I just wanted to extend the coffee offer to you too pdkv2. Thank you both for taking the time to help me get this resolved. On to the next project! Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459476 Share on other sites More sharing options...
pdkv2 Posted February 6, 2008 Share Posted February 6, 2008 Thanks very much Murdock for your coffee offer if you just help the ppl on the board, i assume i had a coffee. Cheers! Sharad ! Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459481 Share on other sites More sharing options...
laffin Posted February 6, 2008 Share Posted February 6, 2008 Yep, I like helping ppl who want to learn Virtual coffee for everyone Quote Link to comment https://forums.phpfreaks.com/topic/89528-solved-pagination-blues-passing-multiple-vars/#findComment-459545 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.