Jump to content

Recommended Posts

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

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 !

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!

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

 

 

 

 

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.