php复选框代码(PHP之多条件混合筛选功能的实现方法)
类别:编程学习 浏览量:1525
时间:2021-10-12 00:23:32 php复选框代码
PHP之多条件混合筛选功能的实现方法如下所示:
|
<style type= "text/css" > .search_text{ overflow : hidden ; height : 100% ; padding-top : 5px ; padding-bottom : 5px ;} .search_text h 1 { 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> |
|
< li class = "search_text" id = "year" > < h1 >生产年度:</ 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 > </ li > < li 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" >机采棉</ a ></ li > </ li > </ ul > </ li > < li 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 > </ li > < li 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 > </ li > < li 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 > </ li > |
|
<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中获取到$where条件,加入到SQL语句中获取数据列表。
以上这篇PHP之多条件混合筛选功能的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/netuser1937/article/details/54572297
您可能感兴趣
- php使用yield处理并发(Yii框架中使用PHPExcel的方法分析)
- php获取数组中和为指定数的数组(php统计数组不同元素的个数的实例方法)
- php中变量定义规则(php use和include区别总结)
- thinkphp源码上传(ThinkPHP框架实现FTP图片上传功能示例)
- php设置上传文件代码(PHP大文件切割上传并带进度条功能示例)
- php回收机制(PHP session垃圾回收机制实例分析)
- phpstudy如何域名访问(phpStudy2016 配置多个域名期间遇到的问题小结)
- phpstudy服务器怎么设置(phpstudy本地环境开启.htaccess伪静态方法)
- php 会话session实现用户登录功能(PHP cookie,session的使用与用户自动登录功能实现方法分析)
- php秒杀实现代码(php无限极分类实现方法分析)
- php语法分析方法(PHP中localeconv函数的用法)
- php闰年计算公式(php判断/计算闰年的方法小结三种方法)
- php7.4类型属性实例详解(PHP 7.4中使用预加载的方法详解)
- php7.4 废弃功能(浅析PHP7 的垃圾回收机制)
- php字符串教程学习(php学习笔记之字符串常见操作总结)
- php用什么解压(php解压缩zip和rar压缩包文件的方法)
- 你喜欢足球吗 足球如何点亮世界的(足球如何点亮世界的)
- 不可分鸽是什么梗(不可分鸽是什么梗)
- 古代的鸽子是爱情的象征,并非和平的使者(古代的鸽子是爱情的象征)
- 一课译词 放鸽子(一课译词放鸽子)
- 终于来了,淘宝更改账户名测试中,快去看看你能不能修改(淘宝更改账户名测试中)
- 淘宝支持账号名修改,网友 终于可以 重新做人 了(淘宝支持账号名修改)
热门推荐
- CSS错误排查方法
- javascript执行类的所有方法(Javascript中异步等待的深入理解)
- vue应用转flutter(Vue和Flask通信的实现)
- vue基础语法对象(浅析从面向对象思维理解Vue组件)
- php教程字符串类型进阶技术教程(PHP中有关长整数的一些操作教程)
- JS函数前面感叹号的作用
- python爬百度api有次数限制吗(对python借助百度云API对评论进行观点抽取的方法详解)
- python爬虫爬取网页信息教程(python爬虫爬取微博评论案例详解)
- dedecms用什么来调用文章描述(织梦DEDECMS文档关键词频率不能修改的解决方法)
- reactmap给了key仍然提示错误(react为什么不推荐使用index作为key)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9