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
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?

Link to comment
Share on other sites

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;
    	
          }
      }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.