我想请一些帮助。
我发送了一个来自多选字段的GET请求,将所选值发送到我的进程页面(archive.php)
<form id="form1" class="four columns" action="archive.php" method="get" name="form1">
<select id="select2" multiple="multiple" name="location[]">
<option value="103001000">value1</option>
<option value="103002000">value2</option>
<option value="103003000">value3</option>
<option value="103004000">value4</option>
</select>
我在我的网址上选择了这样的位置
location[]=103002000&location[]=103003000
并在archive.php中我试图从数据库中获取数据
if (( isset($_GET['location']) && !empty($_GET['location']) )) {
die(var_dump($_GET['location'])); // the var_dump doesn't return an array at all
$loc = implode(', ', $_GET['location']);
$sql="SELECT * FROM locations WHERE AreaID IN (". $loc.")";
}
但是我收到以下错误:错误:'where子句'中的未知列'Array'。
我该如何解决这个问题?
答案 0 :(得分:0)
尝试如下,它可能很简单
if (( isset($_GET['location']) && !empty($_GET['location']) )) {
die(var_dump($_GET['location'])); // the var_dump doesn't return an array at all
//$loc = implode(', ', $_GET['location']);
$_GET['location'] = array('first'=>'loc1','second'=>'loc2','third'=>'loc3');
$loc = implode('","', $_GET['location']);
$loc ='"'.$loc.'"';
$sql='SELECT * FROM locations WHERE AreaID IN ('.$loc.')';
echo $sql;
}
结果查询
SELECT * FROM locations WHERE AreaID IN ("loc1","loc2","loc3")