Destoon set a custom search method _php Instance

Source: Internet
Author: User
Tags chr

First step:

Add two functions to 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 = "<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) {
    //* Split 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 filtering a space carriage return

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

Step Two:

$day = Isset ($day) in the module/sell/search.inc.php? Intval ($day): 0; Insert below

$chengse = Isset ($CHENGSE) intval ($CHENGSE): 0;

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

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

Then use 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.