佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > PHP之多條件混合篩選功能的實(shí)現(xiàn)方法

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

熱門(mén)標(biāo)簽:團(tuán)購(gòu)網(wǎng)站 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 阿里云 Linux服務(wù)器 服務(wù)器配置

如下所示:

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>顏 色 級(jí) :/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級(jí)/a>/li>
   li>a href="javascript:goSort('colors',2);" rel="external nofollow" >白棉2級(jí)/a>/li>
   li>a href="javascript:goSort('colors',3);" rel="external nofollow" >白棉3級(jí)/a>/li>
   li>a href="javascript:goSort('colors',4);" rel="external nofollow" >白棉4級(jí)/a>/li>
   li>a href="javascript:goSort('colors',5);" rel="external nofollow" >白棉5級(jí)/a>/li>
   li>a href="javascript:goSort('colors',6);" rel="external nofollow" >淡點(diǎn)污棉1級(jí)/a>/li>
  /ul>
/div>
div class="search_text" id="lengths">
  h1>長(zhǎng) 度 級(jí) :/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;istring_array.length;i++){
      if(!(string_array[i].indexOf(name)==-1)){
        repeatField = true;//如果有重復(fù)篩選條件,替換條件值
        newUrl = oldUrl.replace(string_array[i],name+"="+value);
      }
    }
    //如果沒(méi)有重復(fù)的篩選字段
    if(repeatField == false){
      newUrl = oldUrl+""+name+"="+value;
    }
  }else{//如果還沒(méi)有篩選條件
    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;istring_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語(yǔ)句中獲取數(shù)據(jù)列表。

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

您可能感興趣的文章:
  • 利用PHP訪問(wèn)數(shù)據(jù)庫(kù)_實(shí)現(xiàn)分頁(yè)功能與多條件查詢功能的示例
  • laravel多條件查詢方法(and,or嵌套查詢)
  • 基于JavaScript實(shí)現(xiàn)前端數(shù)據(jù)多條件篩選功能

標(biāo)簽:衡水 棗莊 萍鄉(xiāng) 江蘇 蚌埠 大理 衢州 廣元

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《PHP之多條件混合篩選功能的實(shí)現(xiàn)方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    射洪县| 滨海县| 宁海县| 芮城县| 永吉县| 惠安县| 鄂州市| 鹿邑县| 黄梅县| 陕西省| 江油市| 中山市| 蓬莱市| 聊城市| 朔州市| 崇州市| 康保县| 恭城| 东乡县| 蓝田县| 赤城县| 万年县| 丹棱县| 读书| 乌审旗| 万州区| 富裕县| 辉县市| 鹤峰县| 宜阳县| 荣昌县| 开江县| 资中县| 津市市| 垦利县| 房产| 连平县| 东乌珠穆沁旗| 衡东县| 敦煌市| 克什克腾旗|