|
Spreadsheet_Excel_Writer error with close
I am trying to clean up code that wasn't created by me and the customer has decided they want the same query to be run but different locations to be put on a different worksheet. So instead of writing it out 6 times, I've created a function that is in an include file:
NB: I've snipped the function as it is huge...
php Code:
Original
- php Code |
|
|
|
function unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls){ $statement_sql1 = " select distinct question_id, question_number, question_text, 'x' rank, unit_code, unit_title, (sum(rank_one) * 1 + sum(rank_two) * 2 + sum(rank_three) * 3 + sum(rank_four) * 4 + sum(rank_five) * 5) mean_total, null stdev, (sum(rank_one) + sum(rank_two) + sum(rank_three) + sum(rank_four) + sum(rank_five)) responses, sum(rank_one),sum(rank_two),sum(rank_three),sum(ra nk_four),sum(rank_five) from results_detailed_aggregated where location_code = '$campus' and schedule_id = $schedule_id and question_type = 'M' "; //echo "<p>"; $statement_sql1 .= " group by unit_code, question_id, question_number, question_text, unit_title order by unit_code, question_number"; //echo $statement_sql1; $statement = OCIParse($conn, $statement_sql1); //$prevUnitCode = NULL; $currentQuestNo = 0; $noRows = 0; //echo $totalRecords . ", " . $noRows . "<br>"; $flagMan = 1; $currentUnitCode = OCIResult($statement, 'UNIT_CODE'); $noRows++; //echo $row . "<br>"; //echo $prevUnitCode . ", " . $currentUnitCode . "<br>"; if ($noRows > 1){ if($prevUnitCode != $currentUnitCode){ $SQLMaxTotalResponse = "select max(total_responses) as maxtotal from results_detailed_aggregated where location_code = 'ALL' and schedule_id = $schedule_id and question_type = 'M' and unit_code = '$prevUnitCode'"; $statementMaxTotal = OCIParse($conn, $SQLMaxTotalResponse); $maxTotalResponseCount = OCIResult($statementMaxTotal, 'MAXTOTAL'); } } $sheet[$currentSheet]->write($row, 0, $prevUnitCode, $format_col_head); $sheet[$currentSheet]->write($row, 1, $prevUnitTitle, $format_col_head); $sheet[$currentSheet]->write($row, 2, $maxTotalResponseCount, $format_col_head); $column = 3; //echo '<br>'; //print_r($mean); for($q=1; $q<=$noManQuestions; $q++){ //echo $row . ", " . $column . "<br>"; if ($mean[$q] > 0){ $sheet[$currentSheet]-> writeString($row, $column, sprintf('%03.2f', round($mean[$q], 2)), $format_percent); } $column++; //print_r ($mean[$q]); } $currentQuestNo = 0; if ($noRows != 1){ $row++; } } } $currentQuestNo++; //$noRows++; $prevUnitCode = OCIResult ($statement, 'UNIT_CODE'); $prevUnitTitle = OCIResult($statement, 'UNIT_TITLE'); $total_rank_sum = OCIResult ($statement, 'MEAN_TOTAL'); if (OCIResult($statement, 'RESPONSES') == 0){ $total_response_count = $total_response_count; }else{ $total_response_count = OCIResult ($statement, 'RESPONSES'); } if ($total_response_count == 0) { $mean[$currentQuestNo] = 0; }else{ $mean[$currentQuestNo] = $total_rank_sum / $total_response_count; }; $mean[$currentQuestNo] = sprintf("%03.2f", $mean[$currentQuestNo]); } //end while } //end if }
The from main page I call the function (all the parameters have been set earlier):
php Code:
Original
- php Code |
|
|
|
$xls = &new Spreadsheet_Excel_Writer (); $xls->setVersion (8); $worksheet = "Core - Overall (ALL)"; $campus = 'ALL'; unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls); $worksheet = 'Core - Campus 1'; $campus = 'Campus1'; unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls); // Send HTTP headers to tell the browser what's coming $xls->send ("university_level_unit_summary_table.xls"); $xls->close();
Now the spreadsheet will be created, except this is displayed in the spreadsheet:
<b>Fatal error</b>: Call to undefined function: close() in <b>/usr/share/pear/Spreadsheet/Excel/Writer/Workbook.php</b> on line <b>510</b><br />
Any ideas?
|