一、增查筆記

來源:互聯網
上載者:User

標籤:

一;上傳圖片時可以列印圖片上傳資訊: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,        );    }

 

一、增查筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.