A problem of a repeated parameter in the pagination links?

后端 未结 5 532
不思量自难忘°
不思量自难忘° 2021-01-16 03:15

The problem is that when I load page 2 for example the URL becomes:

http://domain.com/index.php?restaurant-id=45¤tpage=2

And that\'s fine but when

5条回答
  •  臣服心动
    2021-01-16 03:49

    You could use http_build_query() for this. It's much cleaner than deleting the old parameter by hand.

    It should be possible to pass a merged array consiting of $_GET and your new values, and get a clean URL.

    Untested (can't test right now) but should work:

    $new_data = array("currentpage" => "mypage.html");
    $full_data = array_merge($_GET, $new_data);  // New data will overwrite old entry
    $url = http_build_query($full_data);
    

提交回复
热议问题