2015-04-03 89 views
3

這是我的SQL操作:GROUP_CONCAT - 查詢生成器

select `id_ifc_espaces`,GROUP_CONCAT(DISTINCT `nom_espace`) as nom_espace ,GROUP_CONCAT(DISTINCT `fonction_espace`) as fonction_espace, GROUP_CONCAT(DISTINCT `id_ouvrage_slab_wall`) as id_ouvrage_slab_wall , GROUP_CONCAT(DISTINCT `type_limit`) as type_limit,GROUP_CONCAT(DISTINCT `type_ouvr`) as type_ouvr from `relespouv` group by`id_ifc_espaces` 

這是查詢生成器,我試過:

$relations = DB::table('relespouv') 
->select('id_ifc_espaces') 
->group_by('id_ifc_espaces') 
->where('id_mn','=',$idmn) 
->get(array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace, 
        GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace, 
        GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall, 
        GROUP_CONCAT(DISTINCT type_limit) AS type_limit, 
        GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr '))); 

當我嘗試使用例如nom_espace

$relespouv[$allelement['Relation']][12]=$relation->nom_espace; 

我收到錯誤:

Undefined property: stdClass::$nom_espace

任何人都可以幫助我嗎?

回答

3

您應該get()移動

array(DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace, 
    GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace, 
    GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall, 
    GROUP_CONCAT(DISTINCT type_limit) AS type_limit, 
    GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ') 
) 

select()這樣

$relations = DB::table('relespouv') 
    ->select(array(
     'id_ifc_espaces' 
     DB::raw('GROUP_CONCAT(DISTINCT nom_espace) as nom_espace, 
     GROUP_CONCAT(DISTINCT fonction_espace) AS fonction_espace, 
     GROUP_CONCAT(DISTINCT id_ouvrage_slab_wall) AS id_ouvrage_slab_wall, 
     GROUP_CONCAT(DISTINCT type_limit) AS type_limit, 
     GROUP_CONCAT(DISTINCT type_ouvr) AS type_ouvr ') 
    )) 
    ->group_by('id_ifc_espaces') 
    ->where('id_mn','=',$idmn) 
    ->get(); 
+0

感謝這個解決它 – 2015-04-03 14:33:54

+0

@YOSRABENSALAH樂意幫助,你能接受我的答案,如果它幫助:) – 2015-04-03 14:34:59