本文实例讲述了ThinkPHP使用getlist方法实现数据搜索功能。分享给大家供大家参考,具体如下:
自己在ThinkPHP之中的model之中书写getlist方法,其实所谓的搜索功能无非就是数据库查询之中用到的like %string%,或者其他的 字段名=特定值,这些sql语句拼接在and语句之中;
HTML之中:
订单号: | 下单日期: |
至 交易完成日期 至 订单金额: 至 |
|||||
采购商名称: | 采购商账号: | ||||||
看到没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']