怎么在ThinkPHP中使用getlist方法實(shí)現(xiàn)數(shù)據(jù)搜索功能?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、扎蘭屯網(wǎng)絡(luò)推廣、重慶小程序開(kāi)發(fā)公司、扎蘭屯網(wǎng)絡(luò)營(yíng)銷、扎蘭屯企業(yè)策劃、扎蘭屯品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供扎蘭屯建站搭建服務(wù),24小時(shí)服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.comHTML之中:
看到?jīng)]GET方法提交表單,這個(gè)是查詢條件填入選項(xiàng);
控制器之中:
$order_msg=$order->getList(); $this->assign('info',$order_msg);//這個(gè)獲取訂單的詳細(xì)信息
Model之中:
public function getList($pagesize=25){ $tableName = $this->getTableName(); $where = $tableName.'.service_id = '.$_SESSION['service_site']['service_id']; if(!empty($_GET['order_sn'])){//查詢訂單號(hào) $where.= " and $tableName.`order_sn` like '%".$_GET['order_sn']."%'"; } if(!empty($_GET['count_price_min'])){//查詢訂單最小金額 $where.= " and $tableName.count_price >=".$_GET['count_price_min'].""; } if(!empty($_GET['begintime'])){//下單開(kāi)始日期搜索 $_GET['begintime']=strtotime($_GET['begintime']);//將日期轉(zhuǎn)為時(shí)間戳 $where.= " and $tableName.add_time >=".$_GET['begintime'].""; $_GET['begintime']=date('Y-m-d',$_GET['begintime']);//將日期轉(zhuǎn)為時(shí)間戳 } if(!empty($_GET['endtime'])){//下單結(jié)束日期搜索 $_GET['endtime']=strtotime($_GET['endtime']);//將日期轉(zhuǎn)為時(shí)間戳 $where.= " and $tableName.add_time <=".$_GET['endtime'].""; $_GET['endtime']=date('Y-m-d',$_GET['endtime']);//將時(shí)間戳轉(zhuǎn)換成日期,方便刷新頁(yè)面后前臺(tái)顯示 } if(!empty($_GET['finishbegintime'])){//交易完成開(kāi)始日期搜索 $_GET['finishbegintime']=strtotime($_GET['finishbegintime']);//將日期轉(zhuǎn)為時(shí)間戳 $where.= " and $tableName.ok_time >=".$_GET['finishbegintime'].""; $_GET['finishbegintime']=date('Y-m-d',$_GET['finishbegintime']);//將日期轉(zhuǎn)為時(shí)間戳 } if(!empty($_GET['finishendtime'])){//交易完成結(jié)束日期搜索 $_GET['finishendtime']=strtotime($_GET['finishendtime']);//將日期轉(zhuǎn)為時(shí)間戳 $where.= " and $tableName.ok_time <=".$_GET['finishendtime'].""; $_GET['finishendtime']=date('Y-m-d',$_GET['finishendtime']);//將時(shí)間戳轉(zhuǎn)換成日期,方便刷新頁(yè)面后前臺(tái)顯示 } if(!empty($_GET['send'])){//查詢已發(fā)貨預(yù)警訂單,發(fā)貨時(shí)間距離此刻超過(guò)五天 $where.= " and $tableName.send_time < '".(time()-60*60*24*5)."'"; } if(!empty($_GET['doingorder'])){//查詢處理中的訂單 $where.= " and $tableName.status in (0,1)"; } if(!empty($_GET['warningorder'])){//查詢預(yù)警的訂單:已經(jīng)付款且時(shí)間超過(guò)24小時(shí)未發(fā)貨 $where.= " and $tableName.pay_time < '".(time()-60*60*24)."'"; } if(!empty($_GET['warningorder'])){//查詢預(yù)警的訂單:已經(jīng)付款且時(shí)間超過(guò)24小時(shí)未發(fā)貨 $where.= " and $tableName.is_pay = 1 "; } if(!empty($_GET['warningorder'])){//查詢預(yù)警的訂單:已經(jīng)付款且時(shí)間超過(guò)24小時(shí)未發(fā)貨 $where.= " and $tableName.status in (0,1)"; } if(!empty($_GET['count_price_max'])){//查詢訂單較大金額 $where.= " and $tableName.count_price <=".$_GET['count_price_max'].""; } if(!empty($_GET['user_nick_name'])){//查詢采購(gòu)商名稱 $where.= " and fab_user.nick_name like '".$_GET['user_nick_name']."%'"; } if(!empty($_GET['user_name'])){//查詢采購(gòu)商賬號(hào) $where.= " and fab_user.user_name like '".$_GET['user_name']."%'"; } if(!empty($_GET['supplier_nick_name'])){//查詢供應(yīng)商商名稱 $where.= " and fab_supplier.nick_name like '".$_GET['supplier_nick_name']."%'"; } if(!empty($_GET['supplier_name'])){//查詢供應(yīng)商賬號(hào) $where.= " and fab_supplier.supplier_name like '".$_GET['supplier_name']."%'"; } if($_GET['history'] == 1){ $where .= " and {$tableName}.status in (2,3,4) "; } if(($_GET['pay_type'])!=""&&($_GET['pay_type'])!=-1){//查詢支付方式 $where.= " and fab_order_info.pay_type = ".$_GET['pay_type'].""; } if(($_GET['status'])!=""&&($_GET['status'])!=-1){//查詢訂單狀態(tài) $where.= " and fab_order_info.status = ".$_GET['status'].""; } if(!empty($_GET['stime']) && !empty($_GET['etime'])){ $stime = strtotime($_GET['stime']); $etime = strtotime($_GET['etime']) + 24*60*60; $where.= " and ($tableName.`inputtime` between '$stime' and '$etime')"; } $count = $this->where($where)->count(); $this->countNum = $count; $Page = new \Think\Page($count,$pagesize); $this->page = $Page->show(); $limit = $Page->firstRow.','.$Page->listRows; $sql="select $tableName.*,fab_supplier.nick_name as supplier_nick_name,fab_user.nick_name as user_nick_name from ($tableName left join fab_supplier on fab_order_info.supplier_id=fab_supplier.supplier_id) left join fab_user on fab_order_info.user_id=fab_user.user_id where $where order by $tableName.`order_id` desc limit $limit"; $sqls="select sum(fab_order_info.count_price) as order_price,count(fab_order_info.count_price) as order_count from $tableName where $where order by $tableName.`order_id` desc limit $limit"; $this->sql_msg=$this->query($sqls); return $this->query($sql);//訂單詳細(xì)信息 }
你只需要留意那個(gè)GET數(shù)據(jù)獲取,然后進(jìn)行拼接SQL語(yǔ)句;你為何總是拼接錯(cuò)誤呢!?。?/p>
getTableName(); $count = $this->where($where)->count(); $Page = new \Think\Page($count,$pagesize); $this->page = $Page->show(); $limit = $Page->firstRow.','.$Page->listRows; return $this->query("select * from $tableName where $where order by $tableName.`id` asc limit $limit "); } public function getPage(){ return $this->page; } }
精簡(jiǎn)通用版getlist,實(shí)用于分頁(yè)。
getTableName(); $count = $this->where($where)->count(); $Page = new \Think\Page($count,$pagesize); $this->page = $Page->show(); $limit = $Page->firstRow.','.$Page->listRows; return $this->query("select * from $tableName where $where order by $tableName.`id` asc limit $limit "); } public function getPage(){ return $this->page; } }
關(guān)于怎么在ThinkPHP中使用getlist方法實(shí)現(xiàn)數(shù)據(jù)搜索功能問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。