real_escape_string($_GET['idtrf']) : die('IDTRF non specificato.'); // Preparazione della query $query = " SELECT identificationparts.description_identificationparts, identificationparts.article_identificationparts, identificationparts.color_identificationparts, identificationparts.component_identificationparts, identificationparts.material_identificationparts, identificationparts.cmcreportnumber_identificationparts, identificationparts.cmcreportdate_identificationparts, identificationparts.reportof, identificationparts.partsidnumber FROM identificationparts LEFT JOIN partsordercimac ON partsordercimac.arttypeid = identificationparts.arttypeid AND partsordercimac.partsidpicture = identificationparts.partsidnumber WHERE identificationparts.idtrfdetails = '$idtrf' ORDER BY CASE WHEN partsordercimac.partsidcimac IS NULL THEN 9999 ELSE partsordercimac.partsidcimac END "; $result = $conn->query($query); if (!$result) { die("Errore nell'esecuzione della query: " . $conn->error); } // Creazione del file CSV header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="lista_parti.csv"'); $output = fopen("php://output", "w"); // Intestazioni delle colonne per il CSV $colonne = [ 'description_identificationparts', 'article_identificationparts', 'color_identificationparts', 'component_identificationparts', 'material_identificationparts', 'cmcreportnumber_identificationparts', 'cmcreportdate_identificationparts', 'reportof', 'partsidnumber' ]; // Scrivi le intestazioni delle colonne nel file CSV fputcsv($output, $colonne); // Inserimento dei dati nel file CSV while ($row = $result->fetch_assoc()) { fputcsv($output, [ $row['description_identificationparts'], $row['article_identificationparts'], $row['color_identificationparts'], $row['component_identificationparts'], $row['material_identificationparts'], $row['cmcreportnumber_identificationparts'], $row['cmcreportdate_identificationparts'], $row['reportof'], $row['partsidnumber'] ]); } fclose($output); $conn->close(); exit();