可添加多级筛选功能
<!--s-->
<script type="text/javascript">
function Filter(a,b){
var $ = function(e){return document.getElementById(e);}
var ipts = $('filterForm').getElementsByTagName('input'),result=[];
for(var i=0,l=ipts.length;i<l;i++){
if(ipts[i].getAttribute('to')=='filter'){
result.push(ipts[i]);
}
}
if($(a)){
$(a).value = b;
for(var j=0,len=result.length;j<len;j++){
if(result[j].value==''){
result[j].parentNode.removeChild(result[j]);
}
}
document.forms['filterForm'].submit();
}
return false;
}
</script>
<form id="filterForm" action="jdal.php" method="GET">
<!--
form的id 要和程序里统一
为避免与其他使用的隐藏域冲突,添加了to属性
以下是筛选字段隐藏域
需要筛选的隐藏域需要加 to 属性
-->
<input to="filter" type="hidden" id="fengge" name="fengge" value="a链接提交过来的值" />
<input to="filter" type="hidden" id="mianji" name="mianji" value="a链接提交过来的值" />
</form>
<!--$_GET["fengge"]=="链接的值"设置点击状态 -->
<a href="javascript:Filter('fengge','提交给表单的值')" <?php if($_GET["fengge"]=="链接的值"){echo $class ;} ?>>现代简约<sup></sup></a>
php拼接SQL语句
<?php
$sqlwhere = "";
if($_GET['fengge']){
$sqlwhere.=" AND fengge ='{$_GET['fengge']}' ";
}
if($_GET['mianji']){
switch ($_GET['mianji']) {
case 0:
$sqlwhere.="and mianji>0 and mianji<=200 ";
break;
case 1:
$sqlwhere.="and mianji>0 and mianji<=60 ";
break;
case 2:
$sqlwhere.="and mianji>60 and mianji<=90 ";
break;
case 3:
$sqlwhere.="and mianji>90 and mianji<=120 ";
break;
case 4:
$sqlwhere.="and mianji>120 and mianji<=150 ";
break;
case 5:
$sqlwhere.="and mianji>150 and mianji<=200 ";
break;
default:
break;
}
}
if($_GET['id']==""){
$result=mysql_query("SELECT * FROM cool_content where cat_id in(221) $sqlwhere ORDER BY add_time desc");
}else{
$result=mysql_query("SELECT * FROM cool_content where cat_id='$cat_id' ORDER BY add_time desc");
}
最后更新于 2017-09-01 13:21:05 并被添加「」标签,已有 678 位童鞋阅读过。
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处
此处评论已关闭