sql查询数组中的条件查询
$string="afdsfsdafeseinatdaflklkj"$stringarray=explode('',$string);然后我要用这个分开后的数组去查询数据...
$string = "afdsf sdaf ese in at daf lklkj"
$stringarray=explode(' ', $string);
然后我要用这个分开后的数组去查询数据库跟这个数组里的元素相关的产品怎么写查询,这个数组里面有in,at关键字有关系吗 展开
$stringarray=explode(' ', $string);
然后我要用这个分开后的数组去查询数据库跟这个数组里的元素相关的产品怎么写查询,这个数组里面有in,at关键字有关系吗 展开
1个回答
展开全部
将数组分隔, and or 查询
这个是我之前写的一个数组查询的,你可以看下
$where="";
$jd_name=$_POST['jdname'];
if($jd_name){
$where=$where." and (title like '%".$jd_name."%')";
}
$jgqj=$_POST['jgqj'];
if($jgqj){
$str = $jgqj;
$arr = explode(",",$str);
$len=count($arr);
if($len=="1"){
foreach($arr as $u){
$strarr = explode("_",$u);
$tj=" price between ".$strarr[0]." and ".$strarr[1]." ";
}
}else{
foreach($arr as $u){
$strarr = explode("_",$u);
$tj=$tj." price between ".$strarr[0]." and ".$strarr[1]." or ";
}
}
$ntj=rtrim($tj, "or ");
$where=$where." and (".$ntj.")";
}
$pj=$_POST['pj'];
if($pj){
$str1=$pj;
$arr1=explode(",",$str1);
foreach ($arr1 as $k){
$xj=$xj." xingji=".$k." or ";
}
$nxj=rtrim($xj, "or ");
$where=$where." and (".$nxj.")";
}
$jdtype=$_POST['jdtype'];
if($jdtype){
$str2=$jdtype;
$arr2=explode(",",$str2);
foreach ($arr2 as $ke){
$type=$type." jdtype='".$ke."' or ";
}
$ntype=rtrim($type, "or ");
$where=$where." and (".$ntype.")";
}
$ss=$_POST['ss'];
if($ss){
$str3=$ss;
$arr3=explode(",",$str3);
foreach ($arr3 as $key){
$sheshi=$sheshi." sheshi like '%".$key."%' or ";
}
$nsheshi=rtrim($sheshi, "or ");
$where=$where." and (".$nsheshi.")";
}
$pf=$_POST['pf'];
if($pf){
$where=$where.$pf;
}
$ziduan=$_POST['ziduan'];
if($ziduan){
if($ziduan=="jg"){
$order=" order by price";
}elseif($ziduan=="xj"){
$order=" order by xingji";
}elseif($ziduan=="dp"){
$order=" order by id";
}
}
$shunxu=$_POST['shunxu'];
if($shunxu){
if($shunxu=="1"){
$order=$order." asc";
}else{
$order=$order." desc";
}
}
$Text="";
$sql1=$empire->query("select classid from {$dbtbpre}enewsclass where classname='$city'");
这个是我之前写的一个数组查询的,你可以看下
$where="";
$jd_name=$_POST['jdname'];
if($jd_name){
$where=$where." and (title like '%".$jd_name."%')";
}
$jgqj=$_POST['jgqj'];
if($jgqj){
$str = $jgqj;
$arr = explode(",",$str);
$len=count($arr);
if($len=="1"){
foreach($arr as $u){
$strarr = explode("_",$u);
$tj=" price between ".$strarr[0]." and ".$strarr[1]." ";
}
}else{
foreach($arr as $u){
$strarr = explode("_",$u);
$tj=$tj." price between ".$strarr[0]." and ".$strarr[1]." or ";
}
}
$ntj=rtrim($tj, "or ");
$where=$where." and (".$ntj.")";
}
$pj=$_POST['pj'];
if($pj){
$str1=$pj;
$arr1=explode(",",$str1);
foreach ($arr1 as $k){
$xj=$xj." xingji=".$k." or ";
}
$nxj=rtrim($xj, "or ");
$where=$where." and (".$nxj.")";
}
$jdtype=$_POST['jdtype'];
if($jdtype){
$str2=$jdtype;
$arr2=explode(",",$str2);
foreach ($arr2 as $ke){
$type=$type." jdtype='".$ke."' or ";
}
$ntype=rtrim($type, "or ");
$where=$where." and (".$ntype.")";
}
$ss=$_POST['ss'];
if($ss){
$str3=$ss;
$arr3=explode(",",$str3);
foreach ($arr3 as $key){
$sheshi=$sheshi." sheshi like '%".$key."%' or ";
}
$nsheshi=rtrim($sheshi, "or ");
$where=$where." and (".$nsheshi.")";
}
$pf=$_POST['pf'];
if($pf){
$where=$where.$pf;
}
$ziduan=$_POST['ziduan'];
if($ziduan){
if($ziduan=="jg"){
$order=" order by price";
}elseif($ziduan=="xj"){
$order=" order by xingji";
}elseif($ziduan=="dp"){
$order=" order by id";
}
}
$shunxu=$_POST['shunxu'];
if($shunxu){
if($shunxu=="1"){
$order=$order." asc";
}else{
$order=$order." desc";
}
}
$Text="";
$sql1=$empire->query("select classid from {$dbtbpre}enewsclass where classname='$city'");
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询