How can I add GET variables to the end of the current page url using a form with php?

前端 未结 2 549
我寻月下人不归
我寻月下人不归 2021-01-21 17:36

I have some database information that is being shown on a page.

I am using a pagination class that uses the $_GET[\'page\'] variable in the url. When you c

相关标签:
2条回答
  • 2021-01-21 17:59

    Try this:

    if (strpos($_SERVER['REQUEST_URI'], '?') !== false)
    {
      $url = $_SERVER['REQUEST_URI'] . '&var=value';
    }
    else
    {
      $url = $_SERVER['REQUEST_URI'] . '?var=value';
    }
    
    <a href="<php echo $url;>">Go</a>
    

    Note that $_SERVER['REQUEST_URI'] gives you current url including query string value.

    0 讨论(0)
  • 2021-01-21 18:25
    $query_string = http_build_query(array_merge($_GET, array('page' => $page)));
    
    0 讨论(0)
提交回复
热议问题