我怎样才能使用PHP的形式添加GET变量到当前页面的结尾? [英] How can I add GET variables to the end of the current page url using a form with php?

查看:81
本文介绍了我怎样才能使用PHP的形式添加GET变量到当前页面的结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据库信息显示在页面上。

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

我正在使用分页类,它在url中使用 $ _ GET ['page'] 变量。当你点击不同的分页锚点标签时,它会将 $ _ GET ['page'] 更改为url中的新数字并显示相应的结果。

I am using a pagination class that uses the $_GET['page'] variable in the url. When you click on a different pagination anchor tag, it changes $_GET['page'] to a new number in the url and shows the corresponding results.

我使用 $ _ GET ['searchby'] $ _ GET [' search_input'] 变量。用户在使用GET的表单上输入他们的搜索条件。然后将这些变量放到url中,以便显示正确的结果。

I have sort and search features which uses the $_GET['searchby'] and $_GET['search_input'] variables. The user enters their search criteria on a form that is using GET. The variables are then put into the url allowing for the correct results to be shown.

我遇到的问题是,每当我点击一个分页链接时, $ _ GET ['page'] 变量结束URL并擦除 $ _ GET ['searchby'] $ _ GET [ 'SEARCH_INPUT'] 。当我提交搜索表单时,它会添加 $ _ GET ['searchby'] $ _ GET ['search_input'] 但会删除 $ _ GET ['page']

The problem I am having is that whenever I click on a pagination link, it adds the $_GET['page'] variable to end of the url and erases $_GET['searchby'] or $_GET['search_input']. When I submit the search form, it adds $_GET['searchby'] and $_GET['search_input'] but erases $_GET['page'].

如何使用锚标记和搜索/排序表单将GET变量添加到当前页面的结尾,而不必删除任何现有的GET变量,而是覆盖它们如果它们是相同的GET变量名称?

How can I add GET variables to the end of the current page url using the anchor tag and search/sort form without having it erase any existing GET variables, but overriding them if they're the same GET variable name?

推荐答案

试试这个:

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>

请注意 $ _ SERVER ['REQUEST_URI'] 给你当前的url,包括查询字符串值。

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

这篇关于我怎样才能使用PHP的形式添加GET变量到当前页面的结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆