如何从两列中获取唯一的值列表?

时间:2019-05-22 05:08:05

标签: php laravel

我有一个名为projectlist的表,如下所示。我想获取每个国家/地区的城市列表以及每个城市的项目列表

-Country    City        Project    
-India      Chennai     Project1    
India       Hyderabad   Project2    
India       Delhi       Project3    
India       Mumbai      Project4    
India       Bangalore   Project5    
USA         Shreveport  Project6    
USA         Chicago     Project7    
USA         New York    Project8    
USA         Huston      Project9    
Germany     Berlin      Project10    
Germany     Munich      Project11    
Germany     Framkfurt   Project12    
India       Hyderabad   Project13    
India       Bangalore   Project14    
USA         Shreveport  Project15    
Germany     Berlin      Project16    
Germany     Munich      Project17    

我的laravel控制器中包含以下代码。我知道以下代码是错误的方法,请通过示例代码指导我。 我想返回此值并在刀片视图中显示

$data4 = DB::table('loksabha2014')
       ->select(
        DB::raw('alliance as alliance','partyname as partyname'),
        DB::raw('count(*) as number'))
       ->groupBy('alliance')
       ->get();

我想在刀片视图中显示如下

城市列表:

India - Chennai, Hyderabad, Delhi, Mumbai, Bangalore    
USA - Shreveport, Chicago, New York, Huston     
Germany - Berlin, Munich, Framkfurt 

项目列表:

Chennai - Project1    
Hyderabad - Project2, Project13    
Delhi - Project3    
Bangalore - Project14    
Shreveport - Project6, Project15    
Chicago - Project7    
New York - Project8     
Huston - Project9     
Berlin - Project10, Project16    
Munich - Project11, Project17    

0 个答案:

没有答案