全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

ThinkPHP使用getlist方法实现数据搜索功能示例

本文实例讲述了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']}" />
          &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相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。


# ThinkPHP  # getlist方法  # 数据  # 搜索功能  # thinkPHP5.1框架路由::get、post请求简单用法示例  # python3编写ThinkPHP命令执行Getshell的方法  # thinkPHP数据查询常用方法总结【select  # find  # getField  # query】  # jquery ajax结合thinkphp的getjson实现跨域的方法  # ThinkPHP采用GET方式获取中文参数查询无结果的解决方法  # thinkphp如何传递GET参数方法详解  # 采购商  # 下单  # 转换成  # 进阶  # 相关内容  # 其他的  # 感兴趣  # 给大家  # 分页  # 表单  # 更多关于  # 所述  # 填入  # 支付方式  # 程序设计  # 精简版  # 你只需要  # 数据库查询  # 操作技巧 


相关文章: 网站制作公司广州有几家,广州尚艺美发学校网站是多少?  高端网站建设与定制开发一站式解决方案 中企动力  如何选择域名并搭建高效网站?  如何快速搭建个人网站并优化SEO?  详解ASP.NET 生成二维码实例(采用ThoughtWorks.QRCode和QrCode.Net两种方式)  制作充值网站的软件,做人力招聘为什么要自己交端口钱?  建站主机与虚拟主机有何区别?如何选择最优方案?  广州网站制作公司哪家好一点,广州欧莱雅百库网络科技有限公司官网?  佛山网站制作系统,佛山企业变更地址网上办理步骤?  建站之星导航配置指南:自助建站与SEO优化全解析  建站VPS推荐:2025年高性能服务器配置指南  如何快速生成凡客建站的专业级图册?  制作电商网页,电商供应链怎么做?  建站之星多图banner生成与模板自定义指南  西安专业网站制作公司有哪些,陕西省建行官方网站?  动图在线制作网站有哪些,滑动动图图集怎么做?  定制建站如何定义?其核心优势是什么?  存储型VPS适合搭建中小型网站吗?  建站上传速度慢?如何优化加速网站加载效率?  如何基于云服务器快速搭建网站及云盘系统?  小型网站制作HTML,*游戏网站怎么搭建?  如何在阿里云虚拟主机上快速搭建个人网站?  php json中文编码为null的解决办法  免费视频制作网站,更新又快又好的免费电影网站?  湖州网站制作公司有哪些,浙江中蓝新能源公司官网?  ,制作一个手机app网站要多少钱?  香港服务器如何优化才能显著提升网站加载速度?  c# Task.Yield 的作用是什么 它和Task.Delay(1)有区别吗  南京网站制作费用,南京远驱官方网站?  网站制作需要会哪些技术,建立一个网站要花费多少?  建站之星微信建站一键生成小程序+多端营销系统  如何用虚拟主机快速搭建网站?详细步骤解析  怎么将XML数据可视化 D3.js加载XML  如何在阿里云完成域名注册与建站?  如何在腾讯云服务器上快速搭建个人网站?  建站之星如何快速解决建站难题?  建站之星与建站宝盒如何选择最佳方案?  东莞专业网站制作公司有哪些,东莞招聘网站哪个好?  网站广告牌制作方法,街上的广告牌,横幅,用PS还是其他软件做的?  无锡制作网站公司有哪些,无锡优八网络科技有限公司介绍?  建站之星如何修改网站生成路径?  如何快速搭建高效简练网站?  郑州企业网站制作公司,郑州招聘网站有哪些?  ,怎么在广州志愿者网站注册?  宁波自助建站系统如何快速打造专业企业网站?  香港服务器网站生成指南:免费资源整合与高速稳定配置方案  企业宣传片制作网站有哪些,传媒公司怎么找企业宣传片项目?  ,想在网上投简历,哪几个网站比较好?  网站视频制作书签怎么做,ie浏览器怎么将网站固定在书签工具栏?  如何快速上传自定义模板至建站之星? 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。