重新排序GET变量

时间:2014-09-19 13:00:37

标签: php methods get

我有一个问题,如何重新加载GET变量..解释起来非常复杂,但我认为显示代码要好得多。

http://URL.com/?product_id=23&year=2013&seite=reporting&action=jahres&report=jahres

但我真的想要这样。

http://URL.com/?seite=reporting&action=jahres&report=jahres&product_id=23&year=2013



<input type="hidden" name="seite" value="reporting"/>
<input type="hidden" name="action" value="jahres"/>
<input type="hidden" name="report" value="jahres"/>

表单的操作只是页面的URL。

GET变量?seite = reporting,&lt; ---我需要始终站在所有其他变量的前面,我该怎么办?

谢谢你的帮助!

4 个答案:

答案 0 :(得分:1)

如果你自己在网址中传递它们,那么放置它们的顺序并不重要。

没关系。您可以添加更多查询字符串参数,也可以按任意顺序删除它们。然后使用$_GET["product_id"]等访问它们并相应地处理。

答案 1 :(得分:1)

GET个变量没有排序,你可以按照你想要的任何顺序放置它们,它仍会得到相同的结果。

答案 2 :(得分:0)

如果您有隐藏输入,您可以在URL中订购这些变量的视图,然后重新定义这些变量的位置,例如:

<input type="hidden" name="seite" value="reporting"/>
<input type="hidden" name="action" value="jahres"/>
<input type="hidden" name="report" value="jahres"/>

你可以这样做:

<form>
 1. First Level in your form
<input type="hidden" name="seite" value="reporting"/>

2. Last level in your form the other variables hidden or not.
    <input type="hidden" name="action" value="jahres"/>
    <input type="hidden" name="report" value="jahres"/>
</form>

如果您想访问变量:

$seite = isset($_GET['seite']) ? $_GET['seite'] : null;

当你按下提交按钮时,表单会隐藏第一个输入,在你的网址中获取GET,但是真的很重要,只是为了stetic!

答案 3 :(得分:0)

您可以将GET变量放入数组

$variables = Array (
[0] => $_GET['one']
[1] => $_GET['two']
[2] => $_GET['three']
);

然后在URL输出中逐个回显它们

$url = "http://website.com/script.php?get1=" . $variables[0] . "&get2=" . $variables[1];