从一次搜索中搜索关键字和代码

时间:2014-02-18 06:05:56

标签: php html search keyword

目前我有2个搜索框,一个用于关键字,另一个用于产品代码。

我想只有一个搜索框,但允许用户搜索关键字和代码。 \

我的search.php文件目前包含:

if(isset($counter)){
    for($r=1;$r<$counter;$r++){
        $division_breadcrumb .= $filters[$r]["div"].$filters[$r]["cats"].'<p class="clear"></p>';
        mysql_free_result($query2);
        unset($_GET['division2'],$data2);
    }
}


//Code or keyword is used   
} elseif (isset($_POST['keyword']) || isset($_POST['code'])){
    $keyword = NULL;
    if(isset($_POST['keyword'])){
        if($_POST['keyword'] != 'keyword' && $_POST['keyword'] != ''){
            if(strpos($_POST['keyword'],' ')!==false){
                $_POST['keyword'] = str_replace(' ', ' +',$_POST['keyword']);
                if((strpos($_POST['keyword'],'s ')!==false) && (strpos($_POST['keyword'],'ss ')===false)) $_POST['keyword'] = str_replace('s ', ' ',$_POST['keyword']);
                if(substr($_POST['keyword'],strlen($_POST['keyword'])-1)=='s') $_POST['keyword'] = substr($_POST['keyword'],0,(strlen($_POST['keyword'])-1));

                $keyword = 'AND MATCH (WEB_InventTable.ItemName,WEB_InventTable.Range,WEB_InventTable.Description) AGAINST ("+'.$_POST['keyword'].'" IN BOOLEAN MODE)';
            }else{
                if(substr($_POST['keyword'],strlen($_POST['keyword'])-1)=='s') $_POST['keyword'] = substr($_POST['keyword'],0,(strlen($_POST['keyword'])-1));
                $keyword = 'AND (ItemName LIKE "% '.$_POST['keyword'].' %" OR ItemName LIKE "'.$_POST['keyword'].' %" OR ItemName LIKE " %'.$_POST['keyword'].'") ';
            }
        }

        if($_POST['keyword'] == 'keyword'){
            $_POST['keyword'] = NULL;
        }
    }

    $code = NULL;
    if(isset($_POST['code'])){
        if($_POST['code'] != 'code' && $_POST['code'] != '' && $_POST['code'] != 'code'){
            $code = 'AND ItemId LIKE "%'.$_POST['code'].'%"';
        }
        if($_POST['code'] == 'code'){
            $_POST['code'] = NULL;
        }
    }

    $link = 'page=Search&amp;keyword='.$_POST['keyword'].'&amp;code='.$_POST['code'];

0 个答案:

没有答案