最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP之多條件混合篩選功能的實現(xiàn)方法

 更新時間:2019年10月09日 16:41:33   作者:孫瑞  
今天小編就為大家分享一篇PHP之多條件混合篩選功能的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如下所示:

<style type="text/css">

.search_text{ overflow:hidden; height:100%; padding-top:5px; padding-bottom:5px;}
.search_text h1{ 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">
  <h1>生產(chǎn)年度:</h1>
  <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">
  <h1>棉花類型:</h1>
  <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" >機(jī)采棉</a></li>
   </li>
  </ul>
</div>
<div class="search_text" id="colors">
  <h1>顏 色 級 :</h1>
  <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">
  <h1>長 度 級 :</h1>
  <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">
  <h1>馬克隆值:</h1>
  <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)//如果已經(jīng)有篩選條件
  {  var repeatField = false;
    for(var i=0;i<string_array.length;i++){
      if(!(string_array[i].indexOf(name)==-1)){
        repeatField = true;//如果有重復(fù)篩選條件,替換條件值
        newUrl = oldUrl.replace(string_array[i],name+"="+value);
      }
    }
    //如果沒有重復(fù)的篩選字段
    if(repeatField == false){
      newUrl = oldUrl+"&"+name+"="+value;
    }
  }else{//如果還沒有篩選條件
    newUrl = oldUrl+"?"+name+"="+value;
  }
  //跳轉(zhuǎn)
  window.location = newUrl;
}
function setSelected(name,value){
  var all_li = $("#"+name).find("li");
  //清除所有l(wèi)i標(biāo)簽的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]);//設(shè)置選中的篩選條件
  }
});
</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中獲取到$where條件,加入到SQL語句中獲取數(shù)據(jù)列表。

以上這篇PHP之多條件混合篩選功能的實現(xiàn)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • centos+php+coreseek+sphinx+mysql之一coreseek安裝篇

    centos+php+coreseek+sphinx+mysql之一coreseek安裝篇

    這篇文章主要介紹了centos+php+coreseek+sphinx+mysql之一coreseek安裝篇的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-10-10
  • Yii2學(xué)習(xí)筆記之漢化yii設(shè)置表單的描述(屬性標(biāo)簽attributeLabels)

    Yii2學(xué)習(xí)筆記之漢化yii設(shè)置表單的描述(屬性標(biāo)簽attributeLabels)

    這篇文章主要介紹了Yii2學(xué)習(xí)筆記之漢化yii設(shè)置表單的描述(屬性標(biāo)簽attributeLabels),非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-02-02
  • laravel框架中路由設(shè)置,路由參數(shù)和路由命名實例分析

    laravel框架中路由設(shè)置,路由參數(shù)和路由命名實例分析

    這篇文章主要介紹了laravel框架中路由設(shè)置,路由參數(shù)和路由命名,結(jié)合實例形式分析了laravel框架中路由的設(shè)置、請求處理、映射、命名等相關(guān)操作技巧,需要的朋友可以參考下
    2019-11-11
  • php微信公眾號開發(fā)之音樂信息

    php微信公眾號開發(fā)之音樂信息

    這篇文章主要為大家詳細(xì)介紹了php微信公眾號開發(fā)之音樂信息,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Laravel使用模型實現(xiàn)like模糊查詢的例子

    Laravel使用模型實現(xiàn)like模糊查詢的例子

    今天小編就為大家分享一篇Laravel使用模型實現(xiàn)like模糊查詢的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-10-10
  • PHP SplObjectStorage使用實例

    PHP SplObjectStorage使用實例

    這篇文章主要介紹了PHP SplObjectStorage使用實例,SplObjectStorage是SPL標(biāo)準(zhǔn)庫中的數(shù)據(jù)結(jié)構(gòu)對象容器,用來存儲一組對象,特別是當(dāng)你需要唯一標(biāo)識對象的時候,需要的朋友可以參考下
    2015-05-05
  • thinkPHP3.1驗證碼的簡單實現(xiàn)方法

    thinkPHP3.1驗證碼的簡單實現(xiàn)方法

    這篇文章主要介紹了thinkPHP3.1驗證碼的簡單實現(xiàn)方法,實例分析了thinkPHP3.1使用圖形類生成驗證碼的相關(guān)技巧,需要的朋友可以參考下
    2016-04-04
  • THINKPHP5.1 Config的配置與獲取詳解

    THINKPHP5.1 Config的配置與獲取詳解

    這篇文章主要介紹了THINKPHP5.1 Config的配置與獲取詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • PHP實現(xiàn)多圖上傳和單圖上傳功能

    PHP實現(xiàn)多圖上傳和單圖上傳功能

    本文通過實例代碼給大家介紹了基于PHP實現(xiàn)多圖上傳和單圖上傳功能,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-05-05
  • thinkPHP3.2使用RBAC實現(xiàn)權(quán)限管理的實現(xiàn)

    thinkPHP3.2使用RBAC實現(xiàn)權(quán)限管理的實現(xiàn)

    這篇文章主要介紹了thinkPHP3.2使用RBAC實現(xiàn)權(quán)限管理的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08

最新評論

嘉黎县| 阳朔县| 永丰县| 周宁县| 来宾市| 通道| 南木林县| 洱源县| 安化县| 从江县| 西乡县| 宾阳县| 金山区| 磴口县| 湄潭县| 临清市| 赣榆县| 阿克陶县| 铜梁县| 克山县| 延川县| 普宁市| 苏尼特右旗| 沾益县| 河津市| 牡丹江市| 汶川县| 法库县| 睢宁县| 浙江省| 杂多县| 宁国市| 依兰县| 湖南省| 武山县| 全南县| 将乐县| 靖江市| 崇文区| 贵定县| 盐亭县|