第一步:
在include/global.fun.php中加入兩個函數
函數一:
function loseSpace($pcon){ $pcon = preg_replace("/ /","",$pcon); $pcon = preg_replace("/ /","",$pcon); $pcon = preg_replace("/ /","",$pcon); $pcon = preg_replace("/\r\n/","",$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="<select name=".$name."><option value= >所有</option>"; $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 .=" <option value=".$n." selected>".$v."</option>"; } else{ $title .=" <option value=".$n.">".$v."</option>"; } } $title .="</select>"; 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)}