如何使用$ _GET在PHP中使用相同名称获取多个参数 [英] How to use $_GET to get multiple parameters using the same name in PHP

查看:81
本文介绍了如何使用$ _GET在PHP中使用相同名称获取多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用复选框搜索我创建的mysql数据库.由于所有复选框都使用相同的名称,因此当我使用$ _GET时,它仅获取URL中的最后一个值.

I'm using checkboxes to search a mysql database I have created. As the checkboxes all use the same name, when I use $_GET, it only gets the last value in the URL.

例如: http://www.website. com/search.php?features = Textures& features = Items& style = Realistic& submit = search

只会返回Items,并且会覆盖Textures.

would only return Items, and would override Textures.

是否可以存储两个值,然后使用这些值搜索我的数据库?

Is there a way to store both the values, and then to use these values to search my database?

推荐答案

PHP在这里有点奇怪.使用其标准格式的数据分析器,必须以[]结尾的控件名称才能访问多个控件.

PHP is a little odd here. Using its standard form data parser, you must end the name of the controls with [] in order to access more than one of them.

<input type="checkbox" name="foo[]" value="bar">
<input type="checkbox" name="foo[]" value="bar">
<input type="checkbox" name="foo[]" value="bar">

将以数组形式提供:

$_GET['foo'][]

如果您不想重命名字段,则需要访问原始数据($_SERVER['REQUEST_URI'])并自行解析(我不建议这样做).

If you don't want to rename the fields, then you will need to get access to the raw data ($_SERVER['REQUEST_URI']) and parse it yourself (not something I'd recommend).

这篇关于如何使用$ _GET在PHP中使用相同名称获取多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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