Destoon Setting a custom search method _php Instance

Source: Internet
Author: User
The first step:

Add two functions to the include/global.fun.php

Function One:

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)," ", $pcon); $pcon = Str_ Replace (CHR), "", $pcon), $pcon = Str_replace (Chr (9), "", $pcon); return $pcon;}

Function Two:

function Select_search ($name, $TB, $fid) {    global $db;    $title = "All ";    $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) {    //split 1| available *=> 1, available     if (! $s) {    continue;     }     List ($num, $word) = Split ("\|", $s);     $result [$num] = $word;    }         foreach ($result as $n = + $v)    {    if ($n = = $fid) {     ". $v." ";    }    else{     ". $v." ";    }    }    $title. = "";    return $title;}

The first function means filter blanks to enter

The second function generates a drop-down list based on the name (custom field) TB (owning model) $fid (currently selected ID).

Step Two:

On the module/sell/search.inc.php of the "= Isset" ($day)? Intval ($day): 0; Next insert

$chengse = Isset ($CHENGSE)? Intval ($CHENGSE): 0;

In the IF ($VIP) $condition. = "and vip>0";

if ($CHENGSE) $condition. = "and chengse= $chengse";

Then use it in the template file:

{Select_search (Chengse,sell, $chengse)}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.