提交的時候記得把默認的值去掉? 才能判斷是否有值..

成都創(chuàng)新互聯(lián)公司2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項目做網(wǎng)站、成都網(wǎng)站制作網(wǎng)站策劃,項目實施與項目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元聶榮做網(wǎng)站,已為上家服務(wù),為聶榮各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
//這個是把三個搜索關(guān)鍵詞作為獨立的因子搜索
function?search(){
if(isset($_POST['id'])??intval($_POST['id'])0){
$sql="select?*?from?tbl??where?id=".intval($_POST['id'])."?";
}
if(isset($_POST['name'])){
$sql.="union?select?*?from?tbl?where?name=".$_POST['name']."?";
}
if(isset($_POST['content'])){
$sql.="union?select?*?from?tbl?where?content?like?'%".$_POST['content']."%'?";
}
$s?=?M('search');
$result=$s-query($sql);
}
}
//以下是把三個搜索當作條件進行搜索??有篩選的味道
function?search(){
$where="1=1";
if(isset($_POST['content'])){
$where.="?and?content?like?'%$_POST[content]%'";
}
if(isset($_POST['content'])){
$where.="?and?name?=?'$_POST[name?]'";
}
if(isset($_POST['id'])??intval($_POST['id'])0){
$where.="?and?id=?'$_POST[id]'";
}
if($where?!=?'1=1'){
$sql="select?*?from?tbl?$where";
}else{
throw?new?Exception('沒有輸入搜索詞');
}
$s?=?M('search');
$result=$s-query($sql);
}
}
PHP要實現(xiàn)關(guān)鍵字查搜索,需要用到like關(guān)鍵字來組合查詢條件
like具體實現(xiàn)方法如下:
例一:
1????$userForm=M('user');????
1????$where['name']=array('like','phpernote%');????
2????$userForm-where($where)-select();
這里的like查詢即為:name like 'phpernote%'
例二:
1$where['name']=array('like',array('%phpernote%','%.com'),'OR');
這里的like查詢即為:name like '%phpernote%' or name like '%.com'
例三:
1$where['name']=array(array('like','%a%'),array('like','%b%'),array('like','%c%'),'phpernote','or');
這里的like查詢即為:(`name` LIKE '%a%') OR (`name` LIKE '%b%') OR (`name` LIKE '%c%') OR (`name` = 'phpernote')
例四:
1$where['_string']='(name?like?"%phpernote%")??OR?(title?like?"%phpernote")'
這里的like查詢即為:name like '%phpernote%' or title like '%phpernote'
或者叫,分詞檢索數(shù)據(jù)庫
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草藥%'
and
'%6%'");
//這樣寫是報錯的;
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草藥%'
or
'%6%'");
//而這樣寫是正確的;奇怪~
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草藥%'
and
id
like
'%6%'");
//這樣寫是正確的;
$res
=
mysql_query("select
*
from
peter
where
id
like
'%中草藥%'
or
id
like
'%6%'");
//這樣寫都是正確的;
以上就是小編為大家?guī)淼膒hp
mysql
like
實現(xiàn)多關(guān)鍵詞搜索的方法全部內(nèi)容了,希望大家多多支持腳本之家~
本文題目:php數(shù)據(jù)庫關(guān)鍵詞搜索 php搜索框查詢數(shù)據(jù)庫
網(wǎng)頁路徑:http://www.chinadenli.net/article2/dooshic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、建站公司、定制網(wǎng)站、App設(shè)計、品牌網(wǎng)站設(shè)計、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)