成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? ThinkPHP使用getlist方法實現數據搜索功能示例
全站頭部文字 我要出現在這里
ThinkPHP使用getlist方法實現數據搜索功能示例 771 2024-01-11   

本文實例講述了ThinkPHP使用getlist方法實現數據搜索功能。分享給大家供大家參考,具體如下:

自己在ThinkPHP之中的model之中書寫getlist方法,其實所謂的搜索功能無非就是數據庫查詢之中用到的like %string%,或者其他的 字段名=特定值,這些sql語句拼接在and語句之中;

HTML之中:

<form action="" method="get">
    <table class="account_table" width="100%" cellpadding="0" cellspacing="0">
      <tr>
        <td style="text-align:right">訂單號:</td>
        <td>
          <input id="Orderid" name="order_sn" class="inp_wid3" type="text" value="{$_GET['order_sn']}"/>
        </td>
        <td style="text-align:right">
          下單日期:
        </td>
        <td colspan="5">
          <input type="text" class="inp_wid2" id="BeginTime" name="begintime" value="{$_GET['begintime']}" />
          至
          <input type="text" class="inp_wid2" id="EndTime" name="endtime" value="{$_GET['endtime']}" />
           交易完成日期
          <input type="text" class="inp_wid2" id="txtFinishedBeginTime" name="finishbegintime" value="{$_GET['finishbegintime']}" />
          至
          <input type="text" class="inp_wid2" id="txtFinishedEndTime" name="finishendtime" value="{$_GET['finishendtime']}" />
           訂單金額:
          <input type="text" class="inp_wid2" id="txtMoneyMin" name="count_price_min" value="{$_GET['count_price_min']}"/>
          至
          <input type="text" class="inp_wid2" id="txtMoneyMax" name="count_price_max" value="{$_GET['count_price_max']}" />
        </td>
      </tr>
      <tr>
        <td style="text-align:right; width:80px">采購商名稱:</td>
        <td style="width:140px">
          <input id="SupermarketName" name="user_nick_name" class="inp_wid3" type="text" value="{$_GET['user_nick_name']}" />
        </td>
        <td style="text-align:right; width:80px">采購商賬號:</td>
        <td style="width:140px">
          <input id="SupermarketZh" name="user_name" class="inp_wid3" type="text" value="{$_GET['user_name']}" />
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <input class="search_btn1" type="submit" value="搜索" id="Search" />
          </td>
      </tr>
    </table>
</form>

看到沒GET方法提交表單,這個是查詢條件填入選項;

控制器之中:

$order_msg=$order->getList();
$this->assign('info',$order_msg);//這個獲取訂單的詳細信息

Model之中:

public function getList($pagesize=25){
     $tableName = $this->getTableName();
   $where = $tableName.'.service_id = '.$_SESSION['service_site']['service_id'];
   if(!empty($_GET['order_sn'])){//查詢訂單號
       $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'])){//下單開始日期搜索
    $_GET['begintime']=strtotime($_GET['begintime']);//將日期轉為時間戳
    $where.= " and $tableName.add_time >=".$_GET['begintime']."";
    $_GET['begintime']=date('Y-m-d',$_GET['begintime']);//將日期轉為時間戳
   }
   if(!empty($_GET['endtime'])){//下單結束日期搜索
     $_GET['endtime']=strtotime($_GET['endtime']);//將日期轉為時間戳
    $where.= " and $tableName.add_time <=".$_GET['endtime']."";
    $_GET['endtime']=date('Y-m-d',$_GET['endtime']);//將時間戳轉換成日期,方便刷新頁面后前臺顯示
   }
   if(!empty($_GET['finishbegintime'])){//交易完成開始日期搜索
    $_GET['finishbegintime']=strtotime($_GET['finishbegintime']);//將日期轉為時間戳
    $where.= " and $tableName.ok_time >=".$_GET['finishbegintime']."";
    $_GET['finishbegintime']=date('Y-m-d',$_GET['finishbegintime']);//將日期轉為時間戳
   }
   if(!empty($_GET['finishendtime'])){//交易完成結束日期搜索
     $_GET['finishendtime']=strtotime($_GET['finishendtime']);//將日期轉為時間戳
    $where.= " and $tableName.ok_time <=".$_GET['finishendtime']."";
    $_GET['finishendtime']=date('Y-m-d',$_GET['finishendtime']);//將時間戳轉換成日期,方便刷新頁面后前臺顯示
   }
   if(!empty($_GET['send'])){//查詢已發貨預警訂單,發貨時間距離此刻超過五天
    $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'])){//查詢預警的訂單:已經付款且時間超過24小時未發貨
    $where.= " and $tableName.pay_time < '".(time()-60*60*24)."'";
   }
   if(!empty($_GET['warningorder'])){//查詢預警的訂單:已經付款且時間超過24小時未發貨
    $where.= " and $tableName.is_pay = 1 ";
   }
   if(!empty($_GET['warningorder'])){//查詢預警的訂單:已經付款且時間超過24小時未發貨
   $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'])){//查詢采購商名稱
    $where.= " and fab_user.nick_name like '".$_GET['user_nick_name']."%'";
   }
   if(!empty($_GET['user_name'])){//查詢采購商賬號
    $where.= " and fab_user.user_name like '".$_GET['user_name']."%'";
   }
   if(!empty($_GET['supplier_nick_name'])){//查詢供應商商名稱
    $where.= " and fab_supplier.nick_name like '".$_GET['supplier_nick_name']."%'";
   }
   if(!empty($_GET['supplier_name'])){//查詢供應商賬號
    $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){//查詢訂單狀態
    $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 ThinkPage($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);//訂單詳細信息
}

你只需要留意那個GET數據獲取,然后進行拼接SQL語句;你為何總是拼接錯誤呢?。?!

<?php
namespace AdminModel;
use ThinkModel;
class KuaidicompanyModel extends Model {
  private $page = "";
  public function getList($pagesize=25){
    $where = '1';
    $tableName = $this->getTableName();
    $count = $this->where($where)->count();
    $Page = new ThinkPage($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;
  }
}

精簡通用版getlist,實用于分頁。

<?php
namespace AdminModel;
use ThinkModel;
class KuaidicompanyModel extends Model {
  private $page = "";
  public function getList($pagesize=25){
    $where = '1';
    $tableName = $this->getTableName();
    $count = $this->where($where)->count();
    $Page = new ThinkPage($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;
  }
}

精簡版MODEL用于數據自動驗證

更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術總結》。

希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。


PHP

主站蜘蛛池模板: 蜜桃成熟时在线看| 亚洲第一区se| 珂尼娜| 胖猫表情包| 刘越| 李采潭全部作品百度| 阴阳先生第一季| 黄姓的研究报告怎么写| 二年级最佳家长评语| 色女孩视频| 意大利斜体| 女王耳光| 翟潇闻个人介绍| 思想道德与法治2023版| 男吸女人奶水视频免费观看| 那些女人电视剧免费观看全集剧情| 抖音在线官网| 金狮| 最佳嫌疑人电影免费观看| 男男女女 电影| 儿媳妇电视剧在线观看| 桐谷| 新亮剑40集免费观看完整版高清| 67pp| 高潮艺术| 扎职| 欲情电影在线看| 爱情三选一| qq经典声音| 宁波电视台| 工业硫酸| 黎明电影| 大地资源中文字幕第3页| 大时代电视剧剧情介绍| 中医基础理论试题题库及答案 | 中女| 网络安全的论文1500字| 抗日电影大突围完整版| dy充值| 非常外父| 美国禁事|

?。。≌鹃L長期在線接?。。?/p>

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103