zoukankan      html  css  js  c++  java
  • thinkphp实现多表查询

    where条件需要有明确那张表

    $where = array(  
      'a.store_id' => $storeId,  
      'a.goods_user\_status' => 1,  
    );  
    
    $goodsRes = Db('goods')  
      ->alias('a')  
      ->join('goods_class b','a.class_id = b.class_id','LEFT')//商品分类  
      ->join('store_class c','a.store_class_id = c.class_id','LEFT')//店铺分类,在个人店铺里的  
      ->field('a.* , b.class_name, c.class_name as store_class_name')  
      ->where($where)  
      ->order('goods_id desc')  
      ->paginate(10);

    thinkphp实现多表查询

       /**
         * 显示资源列表
         *
         * @return 	hinkResponse
         */
        public function index()
        {
            //获取当前店铺id
            $uid = session('home_uid');
            $storeId = db('store')->where('store_uid',$uid)->field('store_uid')->find();
            $storeId = implode(" ",$storeId);
            $storeId = (int)$storeId;
            $where = array(
                'a.store_id' => $storeId,
                'a.goods_user_status' => 1,
            );
            //全部商品
            $goodsRes = Db('goods')
            ->alias('a')
            ->join('goods_class b','a.class_id = b.class_id','LEFT')//商品分类
            ->join('store_class c','a.store_class_id = c.class_id','LEFT')//店铺分类,在个人店铺里的
            ->field('a.* , b.class_name, c.class_name as store_class_name')
            ->where($where)
            ->order('goods_id desc')
            ->paginate(10);
    
            $this->assign([
                'seo_title'=> '店铺商品-' . config('site.WEB_TITLE'),
                'seo_keywords'=> config('site.WEB_KEYWORDS'),
                'seo_desc'=> config('site.WEB_DESCRIPTION'),
                'goodsRes' => $goodsRes,
            ]);
            return $this->fetch('seller_goods/index');
        }
  • 相关阅读:
    Java中Comparable与Comparator的区别
    LeetCode[5] 最长的回文子串
    LeetCode[3] Longest Substring Without Repeating Characters
    LeetCode 7. Reverse Integer
    统计单词出现的次数
    System.arraycopy()和Arrays.copyOf()的区别
    SyncToy
    查看端口占用及进程号
    TCP协议
    python 的日志logging模块学习
  • 原文地址:https://www.cnblogs.com/seanpan/p/13992938.html
Copyright © 2011-2022 走看看