0

I used group concat to retrieve my data from mysql db. when i export those valuse to csv coloumns which used group_concat doesnt show the correct order. please advice where i got wrong

     $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);

below is the screenshot of my output

enter image description here

ex: role1, role2 role 3 are jumbled.

hansi silva
  • 99
  • 1
  • 2
  • 15

0 Answers0