zoukankan      html  css  js  c++  java
  • tp5连表查询时,where语句冲突问题

    今天做连表查询的时候,发现加入where语句时会报该条件不明确的sql错误,有点懵,

    翻找了一些资料,发现是其中两张表有相同的字段名,我又没有指定该where条件是哪张表的该字段。

    修改为where为以下代码即可

    $where = array(
        'a.store_id' => $storeId,
        'a.goods_user_status' => 1,
    );

    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');
    }

  • 相关阅读:
    git---如何解决The authenticity of host can't be established.
    前端模板引擎artTemplate.js
    微信小程序
    小程序的项目结构设计
    拖拽插件SortableJS
    iscroll.js的简单使用方法
    头疼的闭包
    关于setTimeout的妙用前端函数节流
    webpack 加载动态图片
    在React中实现条件渲染的7种方法
  • 原文地址:https://www.cnblogs.com/seanpan/p/11365546.html
Copyright © 2011-2022 走看看