当前位置:首页 » 编程语言 » php条件筛选

php条件筛选

发布时间: 2023-08-25 05:13:23

php 多条件筛选 类似58 京东等商品筛选

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Jquery分类</title>
<script src="jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//品牌
var alink01 = $("#linktype01").find("span");
alink01.click(function () {
alink01.each(function () {
$(this).removeClass("templinkactive").addClass("templink");
});
$(this).removeClass("templink").addClass("templinkactive");
$("#Brand").val($(this).attr("tag"));
SetPara();
})

//价格
var alink02 = $("#linktype02").find("span");
alink02.click(function () {
alink02.each(function () {
$(this).removeClass("templinkactive").addClass("templink");
});
$(this).removeClass("templink").addClass("templinkactive");
$("#Price").val($(this).attr("tag"));
SetPara();
})

//尺寸
var alink03 = $("#linktype03").find("span");
alink03.click(function () {
alink03.each(function () {
$(this).removeClass("templinkactive").addClass("templink");
});
$(this).removeClass("templink").addClass("templinkactive");
$("#Size").val($(this).attr("tag"));
SetPara();
})
});

function SetPara() {
var a = $("#Brand").val();
var b = $("#Price").val();
var c = $("#Size").val();
alert("1.php?a=" + a + "&b=" + b + "&c=" + c);
};
</script>
<style type="text/css">
.templinkactive
{
padding:5px;
text-decoration:none;
background-color: #2788DA;
color:#ffffff;
}
.templink
{
cursor:pointer;
padding:5px;
text-decoration:none;
}
table tr{ height:35px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr id="linktype01">
<td style="width:100px">
<b>笔记本品牌</b>
</td>
<td>
<span class='templinkactive' tag="0">不限</span>
</td>
<td>
<span class='templink' tag="100101">联想(Lenovo)</span>
</td>
<td>
<span class='templink' tag="100102">宏碁(Acer)</span>
</td>
<td>
<span class='templink' tag="100103">华硕(ASUS)</span>
</td>
<td>
<span class='templink' tag="100104">戴尔(DELL)</span>
</td>
<td>
<span class='templink' tag="100105">苹果(Apple)</span>
</td>
<td>
<span class='templink' tag="100106">三星 (SAMSUNG)</span>
</td>
</tr>
<tr id="linktype02">
<td style="width:100px">
<b>价格范围</b>
</td>
<td>
<span class='templinkactive' tag="0">不限</span>
</td>
<td>
<span class='templink' tag="100201">1000-2999</span>
</td>
<td>
<span class='templink' tag="100202">3000-3499</span>
</td>
<td>
<span class='templink' tag="100203">4000-4499</span>
</td>
<td>
<span class='templink' tag="100204">5000-5999</span>
</td>
<td>
<span class='templink' tag="100205">6000-6999</span>
</td>
<td>
<span class='templink' tag="100206">7000及以上</span>
</td>
</tr>
<tr id="linktype03">
<td style="width:100px">
<b>尺寸范围</b>
</td>
<td>
<span class='templinkactive' tag="0" >不限</span>
</td>
<td>
<span class='templink' tag="100301">8.9英寸及以下</span>
</td>
<td>
<span class='templink' tag="100302">11英寸</span>
</td>
<td>
<span class='templink' tag="100303">12英寸</span>
</td>
<td>
<span class='templink' tag="100304">13英寸</span>
</td>
<td>
<span class='templink' tag="100305">14英寸</span>
</td>
<td>
<span class='templink' tag="100306">15英寸及以上</span>
<input type="hidden" id="Brand" value="0" />
<input type="hidden" id="Price" value="0" />
<input type="hidden" id="Size" value="0" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>

Ⅱ php,请问对已知二维数组,根据某个字段添加条件筛选怎么做

第一个方法:新建一个空的数组,再循环该数组,如果distance<10000,就压入新建的数组中。

第二个方法:使用array_filter()方法,

<?php
$array=array(
array('id'=>1,'distance'=>131),
array('id'=>2,'distance'=>13100),
array('id'=>3,'distance'=>13231),
);

functionfilterDistance($arr)
{
return($arr['distance']<10000);
}

$array=array_filter($array,"filterDistance");
var_mp($array);
?>

Ⅲ php 二维数组筛选问题

<?php
$arr = array(
array('id'=>'1','姓名'=>'小白','性别'=>'男','班级'=>'1','总分'=>75),
array('id'=>'2','姓名'=>'小黑','性别'=>'男','班级'=>'1','总分'=>76),
array('id'=>'3','姓名'=>'小明','性别'=>'女','班级'=>'1','总分'=>77),
array('id'=>'4','姓名'=>'小光','性别'=>'女','班级'=>'1','总分'=>80),
array('id'=>'5','姓名'=>'小草','性别'=>'女','班级'=>'1','总分'=>82),
array('id'=>'6','姓名'=>'小丽','性别'=>'男','班级'=>'1','总分'=>90),
array('id'=>'7','姓名'=>'小红','性别'=>'男','班级'=>'1','总分'=>90),
array('id'=>'8','姓名'=>'小蓝','性别'=>'男','班级'=>'1','总分'=>84)
);

//第一次遍历数组筛出男性
//用到循环函数、数组函数:foreach、array_push

$manArr = array();//定义个空数组,一会装男性数据
$topScore = 0;//定义个最高总分,一会在遍历过程顺便获取最高分

foreach($arr as $v){
if($v['性别']=='男'){
//对符合男生条件的数组进行记录
array_push($manArr,$v);//把符合男性条件的数组装进刚定义的空数组
//记录男生最高分的分数
if($v['总分']>$topScore){
$topScore = $v['总分'];
}
}
}
//所以现在$manArr就是所有男性了,array('小白'=>75,...)

//接下来是求出总分最高的,继续用循环的方式取出成绩等于最高分数的
foreach($manArr as $v){
if($v['总分']==$topScore){
echo $v['姓名'] . "\r\n";
}
}

热点内容
在哪里开启密码显示 发布:2025-02-04 18:38:30 浏览:787
怎么查询qq密码 发布:2025-02-04 18:20:10 浏览:512
python编写接口 发布:2025-02-04 18:08:30 浏览:78
怎么给游戏设置密码 发布:2025-02-04 18:03:08 浏览:926
商品存储规划 发布:2025-02-04 17:45:24 浏览:567
ios访问共享 发布:2025-02-04 17:36:33 浏览:335
javabuild 发布:2025-02-04 17:30:19 浏览:592
gnulinux编译 发布:2025-02-04 17:30:18 浏览:132
苏州阿里云服务器专网 发布:2025-02-04 17:21:05 浏览:526
如何学习php 发布:2025-02-04 17:11:55 浏览:389