my problem seems to be with this inner foreach loop that loops through query results array...
foreach ($items as $item)
{
$array_to_write = array($item['ffnumber'], $item['firstname'], $item['surname'], $item['course_name'], $item['class_start'], $item['class_end'], $item['location_name'], $item['instructor_name'], $item['attended'], $item['passed']);
$cart->writeRow($currentRow, 0, $array_to_write);
$currentRow++;
}
Here is the whole code...
<?php
require_once "Spreadsheet/Excel/Writer.php";
// Create Workbook
$xls =& new Spreadsheet_Excel_Writer();
// HTTP Headers
$xls->send('Staff Attendance Report.xls');
// Create Worksheet
$cart =& $xls->addWorksheet('Staff Report');
/* FORMATTING HEADER */
// title text
$titleText = 'Staff Attendance Report';
// create format object
$titleFormat =& $xls->addFormat();
// set the font family
$titleFormat->setFontFamily('Arial');
// set the text to bold
$titleFormat->setBold();
// set the text size
$titleFormat->setSize('16');
// set the text color
$titleFormat->setColor('navy');
// set bottom border width to thick
$titleFormat->setBottom(2);
// set the color of the bottom border
$titleFormat->setBottomColor('navy');
// set the alignment to the special merge value
$titleFormat->setAlign('merge');
// add the title to the top left cell of the worksheet,
// passing it the title string and the form object
$cart->write(0,0,$titleText,$titleFormat);
// add empty cells to merge with
$cart->write(0,1,'',$titleFormat);
$cart->write(0,2,'',$titleFormat);
$cart->write(0,3,'',$titleFormat);
// the row height
$cart->setRow(0,30);
// Set the column width
$cart->setColumn(0,20,20);
/* End Header Formatting */
/* Column Headings FORMATTING */
$colHeadingFormat =& $xls->addFormat();
$colHeadingFormat->setBold();
$colHeadingFormat->setFontFamily('Arial');
$colHeadingFormat->setBold();
$colHeadingFormat->setSize('10');
$colHeadingFormat->setAlign('center');
// An array with the data for the column headings
$colNames = array('FFNumber', 'First Name', 'Surname', 'Course', 'Class Begins', 'Class Ends', 'Location', 'Instructor', 'Attended Exam', 'Passed' );
// Add all the column headings with a single call
// leaving a blank row to look nicer
$cart->writeRow(2,0,$colNames,$colHeadingFormat);
// Cell group to Freeze
$freeze = array(3,0,4,0);
$cart->freezePanes($freeze);
/* End Column Headings Formatting */
// set variable
$ffnumber = $_POST['ffnumber'];
// Connect to DB
include('../../db_connect.php');
// FORMAT FFNUMBER DETAILS
foreach($ffnumber as $k => $m)
{
//echo $k.' => '.$m.'<br />';
// Perform Query
$query = "SELECT * ".
"FROM class AS cl ".
"INNER JOIN ".
"training AS t ".
"ON cl.class_ID = t.class_ID ".
"INNER JOIN ".
"course AS c ".
"ON cl.course_ID = c.course_ID ".
"INNER JOIN ".
"location AS l ".
"ON cl.location_ID = l.location_ID ".
"INNER JOIN ".
"instructor AS i ".
"ON cl.instructor_ID = i.instructor_ID ".
"WHERE t.ffnumber = '$m' ".
"ORDER BY cl.class_start ".
"DESC";
//echo '<p>'.$query.'</p>';
$result = mssql_query($query) or die('Select Query Error');
//echo '<p>R:'.$num_results = mssql_num_rows($result).'</p>';
$items = array();
while ($row = mssql_fetch_assoc($result))
{
$items[] = $row;
}
//print_r($items);
$currentRow=4;
foreach ($items as $item)
{
$array_to_write = array($item['ffnumber'], $item['firstname'], $item['surname'], $item['course_name'], $item['class_start'], $item['class_end'], $item['location_name'], $item['instructor_name'], $item['attended'], $item['passed']);
$cart->writeRow($currentRow, 0, $array_to_write);
$currentRow++;
}
} // end foreach
$titleText .= date('dS M Y');
$xls->close();
?>