我使用group concat从mysql db中检索我的数据。当我将那些valuse导出到csv coloumns时,使用group_concat并没有显示正确的顺序。请告诉我出错的地方
$data = DB::table('festivals')
->leftjoin('namedesgs', 'festivals.id', '=', 'namedesgs.festival')
->leftjoin('vehicles', 'festivals.id', '=', 'vehicles.festival')
->select(DB::raw(" GROUP_CONCAT( DISTINCT vehicles.role SEPARATOR '\n') as role,GROUP_CONCAT( DISTINCT vehicles.size SEPARATOR '\n') as size,festivals.id,festivals.ref_no as ref_no, festivals.camping,festivals.tour_mgr_name,festivals.email,festivals.mobile,festivals.name_address, GROUP_CONCAT(DISTINCT namedesgs.name SEPARATOR '\n') as names,GROUP_CONCAT(DISTINCT namedesgs.designation SEPARATOR '\n') as designations"))
->groupBy('festivals.id')
->get();
$filename = "students.csv";
$handle = fopen($filename, 'w+');
fputcsv($handle, array('ref_no','camping','tour_mgr_name','email','mobile','name_address','names', 'designations','role', 'size'));
foreach ($data as $student)
{
fputcsv($handle, array(
$student->ref_no,
$student->camping,
$student->tour_mgr_name,
$student->email,
$student->mobile,
$student->name_address,
$student->names,
$student->designations,
$student->role,
$student->size,
));
}
fclose($handle);
$headers = array(
'Content-Type' => 'text/csv',
);
return \Response::download($filename, '2017.csv', $headers);
下面的是我输出的屏幕截图
ex:role1,role2角色3混乱。