php條件篩選
Ⅰ 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";
}
}