温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用PHP怎么实现一个多条件混合筛选功能

发布时间:2021-04-17 17:44:00 来源:亿速云 阅读:212 作者:Leah 栏目:开发技术

使用PHP怎么实现一个多条件混合筛选功能?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

<style type="text/css">

.search_text{ overflow:hidden; height:100%; padding-top:5px; padding-bottom:5px;}
.search_text h2{ color:#6a6a6a; font-weight:bold; float:left; font-size:14px; margin:0px; padding:0px;}
.search_text ul{ margin:0; padding:0; list-style:none; float:left; overflow:hidden; height:100%;}
.search_text li{ list-style:none; color:#6a6a6a; float:left; width:80px; padding-left:8px; padding-right:5px; white-space:nowrap}
.search_text li a{ list-style:none; color:#6a6a6a;}
.search_text li a:hover{ list-style:none; color:#fe8f01; font-weight:bold; text-decoration:underline;}
.search_text li.selected{color:#fe8f01; font-weight:bold;}
.search_text li.selected a{color:#fe8f01;}
.search_text li.selected a:hover{color:#fe8f01;}
</style>
<div class="search_text" id="year">
  <h2>生产年度:</h2>
  <ul>
   <li class="selected"><a href="javascript:goSort('year',0)" rel="external nofollow" >全部</a></li>
   <li><a href="javascript:goSort('year',1)" rel="external nofollow" >2015</a></li>
   <li><a href="javascript:goSort('year',2)" rel="external nofollow" >2014</a></li>
  </ul>
</div>
<div class="search_text" id="ctype">
  <h2>棉花类型:</h2>
  <ul>
   <li class="selected"><a href="javascript:goSort('ctype',0);" rel="external nofollow" >全部</a> </li>
   <li><a href="javascript:goSort('ctype',1);" rel="external nofollow" >手采棉</a></li>
   <li><a href="javascript:goSort('ctype',2);" rel="external nofollow" >机采棉</a></li>
   </li>
  </ul>
</div>
<div class="search_text" id="colors">
  <h2>颜 色 级 :</h2>
  <ul>
   <li class="selected"><a href="javascript:goSort('colors',0);" rel="external nofollow" >全部</a> </li>
   <li><a href="javascript:goSort('colors',1);" rel="external nofollow" >白棉1级</a></li>
   <li><a href="javascript:goSort('colors',2);" rel="external nofollow" >白棉2级</a></li>
   <li><a href="javascript:goSort('colors',3);" rel="external nofollow" >白棉3级</a></li>
   <li><a href="javascript:goSort('colors',4);" rel="external nofollow" >白棉4级</a></li>
   <li><a href="javascript:goSort('colors',5);" rel="external nofollow" >白棉5级</a></li>
   <li><a href="javascript:goSort('colors',6);" rel="external nofollow" >淡点污棉1级</a></li>
  </ul>
</div>
<div class="search_text" id="lengths">
  <h2>长 度 级 :</h2>
  <ul>
   <li class="selected"><a href="javascript:goSort('lengths',0);" rel="external nofollow" >全部</a> </li>
   <li><a href="javascript:goSort('lengths',1);" rel="external nofollow" >26CM</a></li>
   <li><a href="javascript:goSort('lengths',2);" rel="external nofollow" >27CM</a></li>
   <li><a href="javascript:goSort('lengths',3);" rel="external nofollow" >28CM</a></li>
   <li><a href="javascript:goSort('lengths',4);" rel="external nofollow" >29CM</a></li>
   <li><a href="javascript:goSort('lengths',5);" rel="external nofollow" >30CM</a></li>
   <li><a href="javascript:goSort('lengths',6);" rel="external nofollow" >31CM</a></li>
   <li><a href="javascript:goSort('lengths',7);" rel="external nofollow" >32CM</a></li>
  </ul>
</div>
<div class="search_text" id="micronaire">
  <h2>马克隆值:</h2>
  <ul>
   <li class="selected"><a href="javascript:goSort('micronaire',0);" rel="external nofollow" >全部</a> </li>
   <li><a href="javascript:goSort('micronaire',1);" rel="external nofollow" >C2</a></li>
   <li><a href="javascript:goSort('micronaire',2);" rel="external nofollow" >B2</a></li>
   <li><a href="javascript:goSort('micronaire',3);" rel="external nofollow" >A</a></li>
   <li><a href="javascript:goSort('micronaire',4);" rel="external nofollow" >B1</a></li>
   <li><a href="javascript:goSort('micronaire',5);" rel="external nofollow" >C1</a></li>
  </ul>
</div>
<script language="javascript">
function getQueryString(){
   var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+","g"));
   if(result == null){
     return "";
   }
   for(var i = 0; i < result.length; i++){
     result[i] = result[i].substring(1);
   }
   return result;
}
function goSort(name,value){
  var string_array = getQueryString();
  var oldUrl = (document.URL.indexOf("cotton.php")==-1)?document.URL+"cotton.php":document.URL;
  var newUrl;
  if(string_array.length>0)//如果已经有筛选条件
  {  var repeatField = false;
    for(var i=0;i<string_array.length;i++){
      if(!(string_array[i].indexOf(name)==-1)){
        repeatField = true;//如果有重复筛选条件,替换条件值
        newUrl = oldUrl.replace(string_array[i],name+"="+value);
      }
    }
    //如果没有重复的筛选字段
    if(repeatField == false){
      newUrl = oldUrl+"&"+name+"="+value;
    }
  }else{//如果还没有筛选条件
    newUrl = oldUrl+"?"+name+"="+value;
  }
  //跳转
  window.location = newUrl;
}
function setSelected(name,value){
  var all_li = $("#"+name).find("li");
  //清除所有li标签的selected类
  all_li.each(function(){
    $(this).removeClass("selected");
  });
  //为选中的li增加selected类
  all_li.eq(value).addClass("selected");
}
$(document).ready(function(){
  var string_array = getQueryString();
  for(var i=0;i<string_array.length;i++){
    var tempArr = string_array[i].split("=");
    setSelected(tempArr[0],tempArr[1]);//设置选中的筛选条件
  }
});
</script>
<?php
/**
*加入搜索条件
*/
$where ="1";
$year_array = array(1=>'2015',2=>'2014');
$ctype_array = array(1=>'0',2=>'1');
$colors_array = array(1=>'0',2=>'1',3=>'2',4=>'3',5=>'4',6=>'5');
$lengths_array = array(1=>'0',2=>'1',3=>'2',4=>'3',5=>'4',6=>'5',7=>'6');
$micronaire_array = array(1=>'0',2=>'1',3=>'2',4=>'3',5=>'4');
   
if(isset($year)&&($year!=0)) $where .= " AND year=".$year_array[$year];
if(isset($ctype)&&($ctype!=0)) $where .= " AND ctype=".$ctype_array[$ctype];
if(isset($colors)&&($colors!=0)) $where .= " AND colors=".$colors_array[$colors];
if(isset($lengths)&&($lengths!=0)) $where .= " AND lengths=".$lengths_array[$lengths];
if(isset($micronaire)&&($micronaire!=0)) $where .= " AND micronaire=".$micronaire_array[$micronaire];
/**
*加入搜索条件
*/
?>

关于使用PHP怎么实现一个多条件混合筛选功能问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI