tp 查操作
一、控制器
// 列表public function lst(){$model = D('Goods');// 獲取帶翻頁的數(shù)據(jù)$data = $model->search();$this->assign(array('data' => $data['data'],'page' => $data['page'],));$this->display();}二,模型
public function search(){/************ 搜索 ****************/$where = array();// 商品名稱的搜索$goodsName = I('get.goods_name');if($goodsName)$where['goods_name'] = array('like', "%$goodsName%");// 價格的搜索$startPrice = I('get.start_price');$endPrice = I('get.end_price');if($startPrice && $endPrice)$where['price'] = array('between', array($startPrice, $endPrice));elseif ($startPrice)$where['price'] = array('egt', $startPrice);elseif ($endPrice)$where['price'] = array('elt', $endPrice);// 上架的搜索$isOnSale = I('get.is_on_sale', -1);if($isOnSale != -1)$where['is_on_sale'] = array('eq', $isOnSale); // 是否刪除的搜索$isDelete = I('get.is_delete', -1);if($isDelete != -1)$where['is_delete'] = array('eq', $isDelete); /***************** 排序 ******************/$orderby = 'id'; // 默認排序字段$orderway = 'asc'; // 默認排序方式$odby = I('get.odby');if($odby && in_array($odby, array('id_asc','id_desc','price_asc','price_desc'))){if($odby == 'id_desc')$orderway = 'desc';elseif ($odby == 'price_asc')$orderby = 'price';elseif ($odby == 'price_desc'){$orderby = 'price';$orderway = 'desc';}}/************ 翻頁 *************/// 總的記錄數(shù)$count = $this->where($where)->count();// 生成翻頁對象$page = new \Think\Page($count, 2);// 獲取翻頁字符串$pageString = $page->show();// 取出當前頁的數(shù)據(jù)$data = $this->where($where)->limit($page->firstRow.','.$page->listRows)->order("$orderby $orderway")->select();//echo $this->getLastSql();return array('page' => $pageString,'data' => $data,);}?
轉(zhuǎn)載于:https://www.cnblogs.com/yexiangwang/p/4967601.html
總結(jié)
- 上一篇: postgres 错误duplicate
- 下一篇: worksteal thread poo