標籤:
一;上傳圖片時可以列印圖片上傳資訊:var_dimp($info); die;
二;查資料庫是可以:可以列印tp組裝的sql語句:echo $this->getLastSql();
三;tp的sql語句拼接:
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‘; } } /************ 翻頁 *************/ // 總的記錄數 $count = $this->where($where)->count(); // 產生翻頁對象 $page = new \Think\Page($count, 2); // 擷取翻頁字串 $pageString = $page->show(); // 取出當前頁的資料 $data = $this->where($where)->limit($page->firstRow.‘,‘.$page->listRows)->order("$orderby $orderway")->select(); //echo $this->getLastSql(); return array( ‘page‘ => $pageString, ‘data‘ => $data, ); }
一、增查筆記