PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 8th, 2007, 12:10 AM
kacjp kacjp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 kacjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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
  1.  
  2. function unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls){
  3. $statement_sql1 = "
  4.         select distinct question_id, question_number, question_text, 'x' rank, unit_code, unit_title,
  5.         (sum(rank_one) * 1 + sum(rank_two) * 2 + sum(rank_three) * 3 + sum(rank_four) * 4 + sum(rank_five) * 5) mean_total,
  6.         null stdev,
  7.         (sum(rank_one) + sum(rank_two) + sum(rank_three) + sum(rank_four) + sum(rank_five)) responses,
  8.         sum(rank_one),sum(rank_two),sum(rank_three),sum(ra  nk_four),sum(rank_five)
  9.         from results_detailed_aggregated
  10.         where location_code = '$campus'
  11.         and schedule_id = $schedule_id
  12.         and question_type = 'M'
  13.         ";
  14.    
  15.    
  16.         //echo "<p>";
  17.         $statement_sql1 .= " group by unit_code, question_id, question_number, question_text, unit_title order by unit_code, question_number";
  18.    
  19.         //echo $statement_sql1;
  20.         $statement = OCIParse($conn, $statement_sql1);
  21.    
  22.        
  23.         if (OCIExecute ($statement)) {
  24.            
  25.             //$prevUnitCode = NULL;
  26.            
  27.             $currentQuestNo = 0;
  28.            
  29.             $noRows = 0;
  30.             while (OCIFetch ($statement)) {
  31.                 //echo $totalRecords . ", " . $noRows . "<br>";
  32.                 $flagMan = 1;
  33.                 $currentUnitCode = OCIResult($statement, 'UNIT_CODE');
  34.                 $noRows++;
  35.                 //echo $row . "<br>";
  36.                 //echo $prevUnitCode . ", " . $currentUnitCode . "<br>";
  37.                 if ($noRows > 1){
  38.                     if($prevUnitCode != $currentUnitCode){
  39.                         $SQLMaxTotalResponse = "select max(total_responses) as maxtotal from results_detailed_aggregated
  40.                             where location_code = 'ALL'
  41.                             and schedule_id = $schedule_id
  42.                             and question_type = 'M'
  43.                             and unit_code = '$prevUnitCode'";
  44.                         $statementMaxTotal = OCIParse($conn, $SQLMaxTotalResponse);
  45.                         If (OCIExecute ($statementMaxTotal)){
  46.                             while (OCIFetch ($statementMaxTotal)){
  47.                                 $maxTotalResponseCount = OCIResult($statementMaxTotal, 'MAXTOTAL');
  48.                             }
  49.                         }      
  50.                         OCIFreeStatement($statementMaxTotal);
  51.                         $sheet[$currentSheet]->write($row, 0, $prevUnitCode, $format_col_head);
  52.                         $sheet[$currentSheet]->write($row, 1, $prevUnitTitle, $format_col_head);
  53.                         $sheet[$currentSheet]->write($row, 2, $maxTotalResponseCount, $format_col_head);
  54.                         $column = 3;
  55.                        
  56.                         //echo '<br>';
  57.                         //print_r($mean);
  58.                         for($q=1; $q<=$noManQuestions; $q++){
  59.                             //echo $row . ", " . $column . "<br>";
  60.                             if ($mean[$q] > 0){
  61.                                 $sheet[$currentSheet]->writeString($row, $column, sprintf('%03.2f',round($mean[$q],2)), $format_percent);
  62.                             }
  63.                             $column++;
  64.                            
  65.                             //print_r ($mean[$q]);
  66.                         }
  67.                         unset($mean);
  68.                         $currentQuestNo = 0;
  69.                         if ($noRows != 1){
  70.                             $row++;
  71.                             }
  72.                     }
  73.                 }
  74.            
  75.                        
  76.                 $currentQuestNo++;
  77.                     //$noRows++;
  78.    
  79.                     $prevUnitCode = OCIResult ($statement, 'UNIT_CODE');
  80.                     $prevUnitTitle = OCIResult($statement, 'UNIT_TITLE');
  81.                     $total_rank_sum = OCIResult ($statement, 'MEAN_TOTAL');
  82.                     if (OCIResult($statement, 'RESPONSES') == 0){
  83.                         $total_response_count = $total_response_count;
  84.                     }else{
  85.                         $total_response_count = OCIResult ($statement, 'RESPONSES');
  86.                     }
  87.                
  88.                     if ($total_response_count == 0) {
  89.                         $mean[$currentQuestNo] = 0;
  90.                     }else{
  91.                         $mean[$currentQuestNo] = $total_rank_sum / $total_response_count;
  92.                     };
  93.                     $mean[$currentQuestNo] = sprintf("%03.2f",$mean[$currentQuestNo]);
  94.                    
  95.             }   //end while
  96.         }   //end if
  97. }
  98.     


The from main page I call the function (all the parameters have been set earlier):
php Code:
Original - php Code
  1.  
  2. $xls = &new Spreadsheet_Excel_Writer ();
  3. $xls->setVersion (8);
  4.  
  5. $worksheet = "Core - Overall (ALL)";
  6. $campus = 'ALL';
  7. unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls);
  8. $worksheet = 'Core - Campus 1';
  9. $campus = 'Campus1';
  10. unitmeansummary ($worksheet, $campus, $schedule_id, $schedule_param_display, $conn, $xls);
  11.  
  12. // Send HTTP headers to tell the browser what's coming
  13. $xls->send ("university_level_unit_summary_table.xls");
  14. $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?

Reply With Quote
  #2  
Old March 8th, 2007, 12:17 AM
kacjp kacjp is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 2 kacjp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: Spreadsheet_Excel_Writer error with close

don't worry - worked it out. Should have been passing &$xls

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Spreadsheet_Excel_Writer error with close


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway