<?php
$host="my_host";
$user="my_report";
$pass="my_pass";
$db_name="my_dbname";
$conn = mysqli_connect($host, $user, $pass, $db_name) or die("Errore connessione");
$query = "SELECT status,deadline,name,description,value FROM tblprojects T1, value FROM tblprojects T1 "
. "LEFT JOIN tblcustomfieldsvalues T2 ON T1.id = T2.relid && fieldid = 23 "
. "LEFT JOIN tblcustomfieldsvalues T3 ON T1.id = T3.relid && fieldid = 21 "
. "ORDER BY T1.id DESC";
$result = mysqli_query($conn, $query) or die("Errore della query " . mysqli_error($conn));
//delete file old
if (file_exists("./export/file.csv")) {
unlink('.//export/file.csv');
}
//Open a file in write-mode (he creates it, if it not exists)
$fp = fopen('./export/file.csv', 'w');
// output the column headings
fputcsv($fp, array('status', 'deadline', 'name', 'description', 'partners', 'email'));
function utf8($value) {
$value = str_replace("\"", "", $value);
return str_replace("<br />", " - ", utf8_encode($value));
}
$venditori = array("", "PINCO", "PALLO", "CAIO", "SEMPRONIO");
// loop over the rows, outputting them
while ($row = mysqli_fetch_assoc($result)) {
$row['value'] = array_search($row['value'], $venditori);
$row['deadline'] = implode("/", array_reverse(explode("-", $row['deadline'])));
fputcsv($fp, array_map("utf8", $row));
}
//close the handler
fclose($fp);