开发者

What is the best method of maintaining a large query string?

In several PHP applications I'm making I need to maintain a very long query string for filters for a table. I only want to change one or more GET variables per filter change, while the rest of the query string stays unchanged.

I have a few ideas on how to do this, including using javascript to build the query string every time a filter is changed, or maintaining the query string in a session variable, changing it from there.

I would like your opinions or experience on how the best way to 开发者_开发技巧do this would be.

Thanks!


If you have all params in GET array, why don't you build a function that makes query string from them?

$params = array('key' => 'val', 'oth' => 'inn');

foreach($params as $key => $param) $string .= '&'.$key.'='.$val;


Yes, use an associative array to store a map of keys to values. Then you can change one easily. These are supported well in both PHP and Javascript, so you're good.

You'll just need to write functions that output the array as a query string.

I did this on a lark once (and now I do it every time): alphabetize (or otherwise order) the parameters in the query string. Why? It will be convenient if the same page always has the same URL/query string. If you write tests, it's easier to assert that query strings match. Otherwise, you will be at the mercy of the associative array implementation's traversal order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜