代码之家  ›  专栏  ›  技术社区  ›  Nuwan Withanage

laravel-无法为mysql列名传递变量值

  •  0
  • Nuwan Withanage  · 技术社区  · 6 年前

    因此,我需要传递一个变量值,而不是mysql表的列名。

    一开始,我从select query return中得到变量值

    public function getSiteGrading($site)
        {                    
            $siteGrading = DB::table('sites')
                        ->select('siteGrading')
                        ->where('code',$site)                    
                        ->get(); 
    
            return $siteGrading;                 
        }
    

    然后我需要使用返回变量值 $siteG 作为另一个选择查询的列名

    public function getItemStatus($itemCode)
        {
            $ordSite = Auth::user()->name;
            $siteG = $this->getSiteGrading($ordSite);
            // dd($siteG);
    
            $mandatory_count = DB::table('item_statuses')
                        ->select('itemCode')
                        ->where('itemCode',$itemCode)
                        ->where($siteG,'M')
                        ->get(); 
                        // dd($mandatory_count);
    
            return $mandatory_count;                 
        }
    

    最后从 getItemStatus() 函数,我在说错误的列名时出现以下错误:

    sqlstate[42s22]:未找到列:“where子句”中的1054未知列“[{”sitegrading“:”s57201“}]”(sql:从itemcode=am0201和[{”sitegrading“:”s57201“}]=m的item状态中选择itemcode)

    0 回复  |  直到 6 年前