自己在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']}" />
                     &nbsp;交易完成日期
                     <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']}" />
                     &nbsp;订单金额:
                     <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 \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);//订单详细信息
       }

你只需要留意那个GET数据获取,然后进行拼接SQL语句;你为何总是拼接错误呢!!!

 <?php
 namespace Admin\Model;
 use Think\Model;
 class KuaidicompanyModel extends Model {

     private $page = "";

     public function getList($pagesize=25){
         $where = '1';
         $tableName = $this->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;
     }
 }

精简通用版getlist,实用于分页。

 <?php
 namespace Admin\Model;
 use Think\Model;
 class KuaidicompanyModel extends Model {

     private $page = "";

     public function getList($pagesize=25){
         $where = '1';
         $tableName = $this->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;
     }
 }

精简版MODEL用于数据自动验证

ThinkPHP之中getlist方法实现数据搜索功能的更多相关文章

  1. ThinkPHP - CURD增删改查 - 实例 - 搜索功能

    模板代码: /** * 搜索数据 * @return 无返回值 */ public function search(){ //判断并接收参数 //姓名 if ( isset($_POST['usern ...

  2. 关于ligerui 中 grid 表格的扩展搜索功能在远程数据加载时无法使用的解决办法

    要想使用grid里的扩展搜索功能,除了要引用ligerui主要的js文件外,还必须引入下面的JS文件: 1.Source\demos\filter\ligerGrid.showFilter.js 2. ...

  3. vue自动完成搜索功能的数据请求处理

    在现在的互联网世界里,自动完成的搜索功能是一个很常见的功能.比如百度.搜狗.360搜索 ... 功能描述一下大概是这个样子的:有一个搜索框,用户在里面输入要查询的条件,系统会“智能”判断用户输完了,然 ...

  4. PHPCMS站内搜索功能实现方法汇总,一文解决PHPCMS站内搜索问题

    1,https://blog.csdn.net/hzw19920329/article/details/80110673 点评:phpcms搜索功能实现方法,作者基于PHPCMS做个门户网站实现站内搜 ...

  5. dede使用方法----实现英文版的搜索功能

    搜索功能在网站中是最常见的一个功能了.我们在用dede做双语网站的时候,默认的会有中文版的搜索功能.但是怎么添加一个英文版的搜索功能.各位看官,方法如下: 1.复制plus目录下的serach.php ...

  6. thinkphp save()方法没有数据,保存失败解决办法

    thinkphp save()方法没有数据保存返回0,保存失败返回false   可以对返回值判断一下就好 $ret = $model->save($data); //var_dump($ret ...

  7. ThinkPHP 整合 PHPExcel ,数据导出功能实现,解决Invalid cell coordinate

    PHPExcel想必大家都不陌生,是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言.可以使用它来读取.写入不同格式的电子表格 本次只做数据导出功能的 ...

  8. C#下利用正则表达式实现字符串搜索功能的方法(转)

    关键字:正则表达式.元字符.字符串.匹配: 1.正则表达式简介:正则表达式提供了功能强大.灵活而又高效的方法来处:.NET框架正则表达式并入了其他正则表达式实现的: 2.字符串搜索:正则表达式语言由两 ...

  9. thinkphp做搜索功能

    一般后台都需要做一些搜索功能,直接上图. 至于前端页面大家自己设计.

随机推荐

  1. jQuery:find()及children()的区别

    1:children及find方法都用是用来获得element的子elements的,两者都不会返回 text node,就像大多数的jQuery方法一样. 2:children方法获得的仅仅是元素一 ...

  2. oracle 数据恢复,只有oradata文件夹里的文件,没有备份文件的数据库恢复,重装系统后,oracle 10g数据库恢复

    格式化重装系统后,才想起来oracle 10g 数据库没有做备份,开始以为很麻烦,没想到数据库恢复的还挺顺利的 恢复方法: 1,把原来的数据库文件备份,(D:\oracle\product\10.2. ...

  3. How to make 9-patch image downloaded from the Network

    Probably everyone, who is in touch with the Android world dealt with 9-patch term. It is an image in ...

  4. gitlab和Django实现push自动更新

    1.设置webhook gitlab->setting->webhook:http://121.143.191.166:7000?token=23028-b396-12e5-9912-ba ...

  5. 自定义View的基本流程

    1.明确需求,确定你想实现的效果2.确定是使用组合控件的形式还是全新自定义的形式,组合控件即使用多个系统控件来合成一个新控件,你比如titilebar,这种形式相对简单,参考:http://blog. ...

  6. (转)Combobox出现System.Data.DataRowView的原因,以及指定ValueMember的时机问题

    原文地址 http://blog.csdn.net/lubiaopan/article/details/5915774 当使用Combobox控件时,出现SelectedValue的值为“System ...

  7. css required,focus,valid和invalid介绍

    本文章来给大家介绍在css3定义required,focus,valid和invalid样式的方法,此方法目前只支持ie9+及ff,gg浏览器哦.css3 提示只适用于高级浏览器:ChromeFire ...

  8. JQuery基础教程:选择元素(上)

    jQuery最强大的特性之一就是它能够简化在DOM中选择元素的任务,DOM中的对象网络与家谱有几分类似,当我们提到网络中元素之间的关系时,会使用类似描述家庭关系的术语,比如父元素.子元素,等等.通过一 ...

  9. Android数据的四种存储方式

    作为一个完成的应用程序,数据存储操作是必不可少的.因此,Android系统一共提供了四种数据存储方式.分别是:SharePreference.SQLite.Content Provider和File. ...

  10. C# 版dll 程序集合并工具

    C# 版dll 程序集合并工具 最近要开发一个控件给同事用,开发中会引用一些第三方DLL,这样交给用户很不方便,希望的效果是直接交付一个DLL文件.网上找了一些资料. 1.       使用 Cost ...