I tweeked this a little and it allowed me to see department name's rather than ID's and also Staff Name's rather than ID's.
<?php
$host = 'localhost';
$user = 'user';
$pass = 'password';
$db = 'test_db';
$table = 'ost_ticket';
$file = 'closedTicketReport';
$link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error());
mysql_select_db($db) or die ("Can not connect.");
$csv_output = "Ticket ID, Department, Priority, Staff Firstname, Staff Surname, Email, Name, Subject, Phone, Status, Source, Reopened, Closed, Created";
$csv_output .= "\n";
$query = "SELECT ost_ticket.ticket_id, ost_department.dept_name, ost_ticket.priority_id, ost_staff.firstname, ost_staff.lastname, ost_ticket.email, ost_ticket.name, ost_ticket.subject, ost_ticket.phone, ost_ticket.status, ost_ticket.source, ost_ticket.reopened, ost_ticket.closed, ost_ticket.created
FROM ost_ticket, ost_staff, ost_department
WHERE ost_staff.dept_id = ost_department.dept_id
AND ost_ticket.staff_id = ost_staff.staff_id";
$result = mysql_query($query);
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_row($result)) {
// where you see 14 below this is the ammount of items selected in the query above
for ($j = 0; $j < 14; $j++) {
$csv_output .= $row. " ,";
}
$csv_output .= "\n";
}
}
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>
I also added this to the SCP tickets.php file to allow me to click to export:
$nav->addSubMenu(array('desc'=>'New Ticket','href'=>'tickets.php?a=open','iconclass'=>'newTicket'));
$nav->addSubMenu(array('desc'=>'Export','href'=>'closedTicketReport.php?a=open','iconclass'=>'attachment'));
//Render the page...