• 一、增查笔记


    一;上传图片时可以打印图片上传信息: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 ThinkPage($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,
            );
        }
  • 相关阅读:
    Bootstrap 3 How-To #1 下载与配置
    一致性哈希算法及其在分布式系统中的应用
    哈希(Hash)与加密(Encrypt)的基本原理、区别及工程应用
    ASP.NET MVC3 系列教程
    浏览器对象模型BOM小结
    使用JS实现图片展示瀑布流效果
    利用JS实现购物网站商品放大镜效果
    js事件机制——事件冒泡和捕获
    js入门篇之正则表达式基础
    随机得到1-20之间的10个不相同的随机数
  • 原文地址:https://www.cnblogs.com/yexiangwang/p/4967769.html
Copyright © 2020-2023  润新知