這篇文章給大家介紹PHP中怎么實(shí)現(xiàn)搜索查詢功能,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

首頁顯示列表方法index()中給一個(gè):
$map=array();//初始化查詢條件
$map=$this->_search();//調(diào)用查詢方法
$total = $this->Model->where ($map)->count(); //這個(gè)主要是用來計(jì)算頁面顯示數(shù)據(jù)條數(shù)的
if ($total == 0) {
$_list = '';
} else {
$_list = $this->Model->where ($map)->limit( $post_data ['first'] . ',' . $post_data ['rows'] )->select();
}然后,就是寫一個(gè)_search():
如:
protected function _search(){
$map = array ();
$post_data = I ( 'post.' );
if ($post_data ['packageid'] != '') {
$map ['packageid'] = array (
'like',
'%' . $post_data ['packageid'] . '%'
);
}
return $map;
}最后,在設(shè)置的“搜索”菜單中,調(diào)用這個(gè)搜索方法。
但是,我做的這個(gè),搜索的同時(shí),還要確保在字段status=0,且printing=0的數(shù)據(jù)中進(jìn)行搜索。
$map=array();
$map=$this->_search();
$total = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->count();
if ($total == 0) {
$_list = '';
} else {
$_list = $this->Model->where ($map)->where(array('status' =>0,'print_status'=>0))->limit( $post_data ['first'] . ',' . $post_data ['rows'] )->select();
}關(guān)于PHP中怎么實(shí)現(xiàn)搜索查詢功能就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
名稱欄目:PHP中怎么實(shí)現(xiàn)搜索查詢功能-創(chuàng)新互聯(lián)
本文地址:http://chinadenli.net/article20/doocco.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、商城網(wǎng)站、全網(wǎng)營(yíng)銷推廣、域名注冊(cè)、企業(yè)網(wǎng)站制作、網(wǎng)頁設(shè)計(jì)公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容