destoon Setting Custom Search Methods
- 2021-07-02 23:45:28
- OfStack
Step 1:
Add two functions in include/global. fun. php
Function 1:
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 2:
function select_search($name,$tb,$fid){
global $db;
$title="<select name=".$name."><option value= > All </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){
// With * Segmentation 1| Available *=> 1, Available
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;
}
The first function means to filter the space carriage return
The second function generates a drop-down list based on name (custom field) tb (model) $fid (currently selected ID).
Step 2:
$day = isset ($day) in module/sell/search. inc. php? intval ($day): 0; Insert below
$chengse = isset($chengse)?intval($chengse):0;
In if ($vip) $condition. = "AND vip > 0 "; Add below
if($chengse) $condition .= " AND chengse=$chengse";
Then use in the template file:
{select_search(chengse,sell,$chengse)}