当前位置: 编程技术>php
destoon自定义搜索怎么设置?destoon自定义搜索设置方法
来源: 互联网 发布时间:2014-08-30
本文导语: destoon自定义搜索怎么设置?destoon自定义搜索设置方法 具体步骤: 第一步: 在include/global.fun.php中加入两个函数 函数一: 代码示例: function loseSpace($pcon){ $pcon = preg_replace("/ /","",$pcon); $pcon = preg_replace("/ /","",$pcon); $pcon = pr...
destoon自定义搜索怎么设置?destoon自定义搜索设置方法
具体步骤:
第一步:
在include/global.fun.php中加入两个函数
函数一:
代码示例:
function loseSpace($pcon){
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/rn/","",$pcon);
$pcon = str_replace(chr(13),"",$pcon);
$pcon = str_replace(chr(10),"",$pcon);
$pcon = str_replace(chr(9),"",$pcon);
return $pcon;
}
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/ /","",$pcon);
$pcon = preg_replace("/rn/","",$pcon);
$pcon = str_replace(chr(13),"",$pcon);
$pcon = str_replace(chr(10),"",$pcon);
$pcon = str_replace(chr(9),"",$pcon);
return $pcon;
}
函数二:
代码示例:
function select_search($name,$tb,$fid){
global $db;
$title="所有";
$r = $db->get_one("SELECT option_value FROM {$db->pre}fields WHERE name='$name' and tb='$tb'");
$option_value=loseSpace($r["option_value"]);
$ps = split("*", $option_value);
#var_dump($matchs);
foreach ($ps as $s){
//以*分割1|可用*=> 1, 可用
if(!$s){
continue;
}
list($num,$word) = split("|", $s);
$result[$num] = $word;
}
foreach($result as $n => $v)
{
if ($n==$fid){
$title .=" ".$v."";
}
else{
$title .=" ".$v."";
}
}
$title .="";
return $title;
}
global $db;
$title="所有";
$r = $db->get_one("SELECT option_value FROM {$db->pre}fields WHERE name='$name' and tb='$tb'");
$option_value=loseSpace($r["option_value"]);
$ps = split("*", $option_value);
#var_dump($matchs);
foreach ($ps as $s){
//以*分割1|可用*=> 1, 可用
if(!$s){
continue;
}
list($num,$word) = split("|", $s);
$result[$num] = $word;
}
foreach($result as $n => $v)
{
if ($n==$fid){
$title .=" ".$v."";
}
else{
$title .=" ".$v."";
}
}
$title .="";
return $title;
}
第一个函数的意思是过滤空格回车
第二个函数是根据 name(自定义字段) tb(所属模型) $fid(当前所选ID)生成下拉列表。
第二步:
在module/sell/search.inc.php中的$day = isset($day) ? intval($day) : 0;
下插入:
代码示例:
$chengse = isset($chengse)?intval($chengse):0;
在if($vip) $condition .= " AND vip>0";下加入:
代码示例:
if($chengse) $condition .= " AND chengse=$chengse";
然后,在模板文件中使用:
代码示例:
{select_search(chengse,sell,$chengse)}
推荐阅读:destoon入门教程与技巧实例