Problems with variable passing in URL

Hi! I’m having a problem with passing variables through URL. I’ll try to explain it - I’m creating a library (which is a list of files with their attributes in different columns). Now there’s 2 functions that I want to implement - the sorting and filtering of data. I can do it separately, however when it comes to joining these 2 functions, it gets really bad. My idea was to pass it through URL, so that each function can save the state of list and only add additional parameters, for example:

title | author | ^ date (sorted by date ASC, so my URL is …/?s_cat=date&s_st=asc)

now if I want to filter data, I want to leave the sorting as it was before, for example:

title | author | ^ date (leave only data where author=John and then sort it by date ASC and URL will be something like this: …/?s_cat=date&s_st=asc&author=John)

But there can also be different variants, like filter data only, so the URL would be …/?author=John

Unfortunately I’m unable to achieve this, and the problem may sound funny, but - what is the best way to determine when to use “?” or “&” when passing variables in the URL ?

$params = array(
echo ''.implode('&', $params);


I think [fphp]http_build_query[/fphp] would be the preferred way, it applies the proper escaping to the query string elements.

$params = array(
    'something' => 'foo',
    'another'   => 'bar'

echo '', http_build_query($params);

Ok, I tried it, bet met some difficulties - when the page is reloaded (because of the parameter passing), the array, which stores valuable data, is completely erased. Can I leave the array as it is and delete only, lets say, user leaves the page?