Jump to content

Why am I getting unexpected } error


u0867587

Recommended Posts

I get parse error unexpected '{' on line 153 (this is last bracket of the code) but all the { brackets are closed. Whats wrong with this code:

 

 

     function outputModule($moduleID, $moduleName, $sessionData)    
      
      {        
    	  
    	  if(!count($sessionData)) { return false; }        
    	  
    	  $markTotal = 0;        
    	  $markGrade = 0;
    	  $weightSession = 0;
    	  $grade = "";
    	  $sessionsHTML = '';  
    	  
    };  
    
    if ($markGrade >70)
        $grade = 'A';
    elseif ($markGrade >=60 && $average <=69)
        $grade = 'B';
    elseif ($markGrade >=50 && $average <=59)
        $grade = 'C';    
    	  
    	  foreach($sessionData as $session)        {           
    		  
    		   $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} {$session['Mark']} {$session['SessionWeight']}%</p>\n";            
    		   $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); 
    		   $weightSession  += ($session['SessionWeight']);  
    		   $markGrade = ($markTotal /  $weightSession * 100);   
    		   
    		   }        
    		   
    		   $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} {$markTotal} {$markGrade} {$grade}</p>\n";       
    		   
    		    return $moduleHTML . $sessionsHTML;    }    
    		    
    		    $output = "";    
    		    
    		    $studentId = false;    
    		    $courseId  = false;    
    		    $moduleId  = false;    
    		    
    		    while ($row = mysql_fetch_array($result))    {               
    			     
    			     if($studentId != $row['StudentUsername'])        {            
    				     
    				     //Student has changed              
    			     $studentId = $row['StudentUsername'];                    
    			     
    			     $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n";          
    			     
    			      }        
    			      
    			     if($courseId != $row['CourseId'])        {            
    				      
    				      //Course has changed           
    				       $courseId = $row['CourseId'];                    
    				       
    				       $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>\n";           
    				       
    				        }      
    				        
    				 if($moduleId != $row['ModuleId'])        {            
    					 
    					 //Module has changed            
    					 if(isset($sessionsAry)) //Don't run function for first record           
    					 
    					  {              
    						  
    						    //Get output for last module and sessions                
    						    $output .= outputModule($moduleId, $moduleName, $sessionsAry);            }            
    						    
    						    //Reset sessions data array and Set values for new module           
    						    
    						     $sessionsAry = array();            
    						     $moduleId    = $row['ModuleId'];         
    						     $moduleName  = $row['ModuleName'];        }        
    						     
    						     //Add session data to array for current module      
    						     
    						     $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']);    
    						     
    						     }    //Get output for last module  
    						     
    						      $output .= outputModule($moduleId, $moduleName, $sessionsAry);   
    						      
    						       //Display the output    
    						       echo $output;
    	
          }
      }

Link to comment
https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/
Share on other sites

    	  foreach($sessionData as $session)        {           
    		  
    		   $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} {$session['Mark']} {$session['SessionWeight']}%</p>\n";            
    		   $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); 
    		   $weightSession  += ($session['SessionWeight']);  
    		   $markGrade = ($markTotal /  $weightSession * 100);   
    		   
    		   }        
    		   
    		   $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} {$markTotal} {$markGrade} {$grade}</p>\n";       
    		   
    		    return $moduleHTML . $sessionsHTML;    }    

last line, where is the open bracket?

look at this too, you dont have opening brackets...

 

    				 if($moduleId != $row['ModuleId'])        {            
    					 
    					 //Module has changed            
    					 if(isset($sessionsAry)) //Don't run function for first record           
    					 
    					  {              
    						  
    						    //Get output for last module and sessions                
    						    $output .= outputModule($moduleId, $moduleName, $sessionsAry);            }            
    						    
    						    //Reset sessions data array and Set values for new module           
    						    
    						     $sessionsAry = array();            
    						     $moduleId    = $row['ModuleId'];         
    						     $moduleName  = $row['ModuleName'];        }        
    						     
    						     //Add session data to array for current module      
    						     
    						     $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']);    
    						     
    						     }    //Get output for last module  
    						     
    						      $output .= outputModule($moduleId, $moduleName, $sessionsAry);   
    						      
    						       //Display the output    
    						       echo $output;
    	
          }
      }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.