开发者

Best way to add/change 1 GET value while keeping others?

How can I make a link that justs 开发者_开发百科adds or changes 1 GET var while maintaining all others?

I have a page that is created using different GET vars.

So it will be like mypage.php?color=red&size=7&brand=some%20brand

So I want to have a link that sets it to page=2 or size=8. Whats the easiest way to have a link do that without reseting all the other vars?

I hope that makes sense, let me know if I need to further explain anything


You can parse the url with parse_str to get the values of the url. You can then build a http query by using http_build_query:

$query_arr = $_GET; //or parse_str($_SERVER['QUERY_STRING'], $query_arr)
$query_arr["page"] = 2;
$query_arr["size"] = 8;

$query = http_build_query($query_arr);

EDIT: Sorry I mixed up the two functions ... its parse_str() of course.


http_build_query

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜