u0867587 Posted November 4, 2011 Share Posted November 4, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/ Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 4, 2011 Share Posted November 4, 2011 your code makes no sense, where is line 153? Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284861 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 4, 2011 Share Posted November 4, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284863 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 4, 2011 Share Posted November 4, 2011 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284864 Share on other sites More sharing options...
floridaflatlander Posted November 4, 2011 Share Posted November 4, 2011 Something is missing I know this isn't it but what's this ? return $moduleHTML . $sessionsHTML; } just below your foreach loop Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284865 Share on other sites More sharing options...
ZulfadlyAshBurn Posted November 4, 2011 Share Posted November 4, 2011 @floridaflatlander if you look at the whole code, there are many more { } errors. Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284867 Share on other sites More sharing options...
AyKay47 Posted November 4, 2011 Share Posted November 4, 2011 bottom line, check your brackets, make sure they line up with the correct beginning bracket.. is this all supposed to be a function? i'm assuming that you want to end your function after your return statement..? Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1284985 Share on other sites More sharing options...
floridaflatlander Posted November 5, 2011 Share Posted November 5, 2011 What happened? Did you get it figured out? Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1285208 Share on other sites More sharing options...
Wiro Blangkon Posted November 5, 2011 Share Posted November 5, 2011 Which IDE are you using? Look for a missing ";" or ")" just before line 153. Quote Link to comment https://forums.phpfreaks.com/topic/250428-why-am-i-getting-unexpected-error/#findComment-1285227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.