当前位置:阳诡子 > 建站 > 正文

PHP单项条件筛选

时间:2020-12-27  来源:  作者:

前言

此效果适用于商城、分类信息等网站的数据列表页,通过自己定义相关的筛选条件,可以使访客更容易、精确地找到想要的信息。

设置筛选条件

以下全码中的“yajinyaoqiu”、“zulinfangshi”、“fukuanyaoqiu”就是相应的筛选条件,可自行根据实际需要修改,但要匹配文中第二段代码中的相应条件!此代码可加入到页面中的<html>标记之前:

<?php
$urlparts = array('yajinyaoqiu', 'zulinfangshi', 'fukuanyaoqiu');
$url = array();
foreach ($_GET as $k=> $v) {
if (in_array($k, $urlparts)) {
$url[$k] = $v;
}
}
function buildurl($url, $name, $value)
{
$url[$name] = $value;
return http_build_query(array_filter($url));
}
?>

设置具体参数

注意以下代码中匹配文中第一段代码的筛选条件参数部分,注意保持一致,在</body>标记之前的相应位置插入即可,放到支持PHP的运行环境中,很快就会明白原理:

押金要求:
<?php if ($url['yajinyaoqiu'] == '1'): ?>面议<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', '1'); ?>">面议</a><?php endif; ?>&nbsp;
<?php if ($url['yajinyaoqiu'] == '2'): ?>半月租金<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', '2'); ?>">半月租金</a><?php endif; ?>&nbsp;
<?php if ($url['yajinyaoqiu'] == '3'): ?>一月租金<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', '3'); ?>">一月租金</a><?php endif; ?>&nbsp;
<?php if ($url['yajinyaoqiu'] == '4'): ?>两月租金<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', '4'); ?>">两月租金</a><?php endif; ?>&nbsp;
<?php if ($url['yajinyaoqiu'] == '5'): ?>一季租金<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', '5'); ?>">一季租金</a><?php endif; ?>&nbsp;
<?php if ($url['yajinyaoqiu'] != ''): ?>[<a href="?classid=2&ph=1&<?php echo buildurl($url, 'yajinyaoqiu', ''); ?>">取消</a>]<?php endif; ?>
<br/>
租赁方式:
<?php if ($url['zulinfangshi'] == '1'): ?>整租<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'zulinfangshi', '1'); ?>">整租</a><?php endif; ?>&nbsp;
<?php if ($url['zulinfangshi'] == '2'): ?>合租<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'zulinfangshi', '2'); ?>">合租</a><?php endif; ?>&nbsp;
<?php if ($url['zulinfangshi'] == '3'): ?>短租<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'zulinfangshi', '3'); ?>">短租</a><?php endif; ?>&nbsp;
<?php if ($url['zulinfangshi'] != ''): ?>[<a href="?classid=2&ph=1&<?php echo buildurl($url, 'zulinfangshi', ''); ?>">取消</a>]<?php endif; ?>
<br/>
付款要求:
<?php if ($url['fukuanyaoqiu'] == '1'): ?>面议<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', '1'); ?>">面议</a><?php endif; ?>&nbsp;
<?php if ($url['fukuanyaoqiu'] == '2'): ?>一月一付<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', '2'); ?>">一月一付</a><?php endif; ?>&nbsp;
<?php if ($url['fukuanyaoqiu'] == '3'): ?>一季一付<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', '3'); ?>">一季一付</a><?php endif; ?>&nbsp;
<?php if ($url['fukuanyaoqiu'] == '4'): ?>半年一付<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', '4'); ?>">半年一付</a><?php endif; ?>&nbsp;
<?php if ($url['fukuanyaoqiu'] == '5'): ?>一年一付<?php else: ?><a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', '5'); ?>">一年一付</a><?php endif; ?>&nbsp;
<?php if ($url['fukuanyaoqiu'] != ''): ?>[<a href="?classid=2&ph=1&<?php echo buildurl($url, 'fukuanyaoqiu', ''); ?>">取消</a>]<?php endif; ?>
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
CopyRight 2008-2022, 529600.Net, Inc.All Rights Reserved
粤ICP备2022094815号-1  网安备案粤公网安备 44178102001207号