Home > Backend Development > PHP Tutorial > How to set up custom search in destoon_PHP tutorial

How to set up custom search in destoon_PHP tutorial

WBOY
Release: 2016-07-13 10:24:15
Original
1303 people have browsed it

Step one:

Add two functions to 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;
}

Copy after login

Function 2:

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;
}

Copy after login

The first function means filtering spaces and carriage returns

The second function is to generate a drop-down list based on name (custom field) tb (model to which it belongs) $fid (currently selected ID).

Step 2:

Insert

under $day = isset($day) ? intval($day) : 0; in module/sell/search.inc.php
$chengse = isset($chengse)&#63;intval($chengse):0;

Copy after login

Add

under if($vip) $condition .= " AND vip>0";
if($chengse) $condition .= " AND chengse=$chengse";

Copy after login

Then in the template file use:

{select_search(chengse,sell,$chengse)}
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825547.htmlTechArticleStep 1: Add two functions to include/global.fun.php Function 1: function loseSpace( $pcon){$pcon = preg_replace("/ /","",$pcon);$pcon = preg_replace("//","",$pcon);$pcon =...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template