views:

36

answers:

1

I have a div on a PHP-generated page loaded through jQuery's .load() function. This div contains a long list which has been paginated (links for page 1, 2, 3... 25, etc.). I'd like to write a function which will preserve the variables in 'search' portion of the URI (which is to say at the end of the URI: ?foo=1&bar=pancakes) and stick on a &page=X at the end. However, to do that, I must somehow retrieve the current URI which loaded the div from within that div.

window.location.search obviously only retrieves information from the parent page, so that's no help. The .js files are loaded in statically, so I can't stick PHP into the middle of the Javascript to set variables. I can't even move the pagination links into the parent page, because I need the number of pages to update when the number of entries in the list changes. I'm at a loss as to how I might accomplish this task. Any suggestions would be greatly appreciated.

EDIT: The links are all handled by jQuery to load the div with the new information -- hence the .load()

A: 

Simply loop through the $_GET variable:

function getvars_to_url_fragment() {
    $ret = "" ;
    $amp = "" ;
    foreach($_GET as $k => $v) {
        $ret .= $amp.urlencode($k)."=".urlencode($v) ;
        $amp = "&" ;
    }
    return $ret ;
}
Gus