Efter at have set din kommentar, og at du bare prøver at lave en CSV ud af den, kan du gøre sådan noget:
<?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);