使用$ _GET请求无法从多个选择中获取值 [英] Can't get the values from multiple select with $_GET request

查看:117
本文介绍了使用$ _GET请求无法从多个选择中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用多选字段的GET请求将选定的值发送到我的proccess页面(archive.php )

 < form id =form1class =four columnsaction =archive.phpmethod =get name =form1> 
< select id =select2multiple =multiplename =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 



  if((isset( $ _GET ['location'])&&!empty($ _ GET ['location']))){
die(var_dump($ _ GET ['location'])); // var_dump根本不返回数组
$ loc = implode(',',$ _GET ['location']);

$ sql =SELECT * FROM locations WHERE AreaID IN(。$ loc。);
}

但是我收到以下错误:Error:Unknown column'Array' in'where clause'。



我该如何解决这个问题?

解决方案

< ($ is)($ _ GET ['location'])&& amp;& amp;& amp;& amp;& amp; ;!empty($ _ GET ['location']))){
die(var_dump($ _ GET ['location'])); // var_dump根本不返回数组
// $ 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)


I'd like some help please.

I'm sending with a GET request from a multiple select field the selected values to my proccess page (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>

I get the selected locations on my url like this

location[]=103002000&location[]=103003000

and in the archive.php I'm trying to fetch data from the database like this

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.")";
}

but I'm getting the following error: Error: Unknown column 'Array' in 'where clause'.

How can I fix this?

解决方案

try with as below it might be simple

 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;
    }

result query

SELECT * FROM locations WHERE AreaID IN ("loc1","loc2","loc3")

这篇关于使用$ _GET请求无法从多个选择中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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