Nadat je je opmerking hebt gezien en je probeert er gewoon een CSV van te maken, kun je zoiets als dit doen:
<?php
$query = $db->query('SELECT ItemID, GROUP_CONCAT(File SEPARATOR \'|$|\') AS Files FROM Table GROUP BY ItemID');
// Use a string that cant appear as part of the filename as the separator
$fh = fopen('items.csv', 'w');
foreach ($query->fetchAll(PDO::FETCH_ASSOC) as $row) {
$files = explode('|$|', $row['Files']);
fputcsv($fh, array_merge(array($row['ItemID']), $files));
}
fclose($fh);