Jump to content

u0867587

Members
  • Posts

    29
  • Joined

  • Last visited

    Never

Posts posted by u0867587

  1. my output is this below:

     

    Course: INFO101 - Bsc Information Communication Technology Course Mark:

     

     

     

    Course: INFO101 - Bsc Information Communication Technology Course Mark:

     

     

    Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

     

    Session: AAB Session Mark: 72 Session Weight Contribution 20%

     

    Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

    Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

     

    Session: AAD Session Mark: 61 Session Weight Contribution 50%

     

    As it shows 2 different Modules, it shows the "Course" details twice, I only want the "Course" details appear once as you can see both course details are the same.

     

    How can I display the "Course" Details only once in the foreach loop.

     

    To display the "Course" details I use this code: echo

    `"<p><br><strong>Course:</strong> {$courseId} - {$courseName} <strong>Course Mark:</strong></p><br>\n";

    `

     

    Below is the code for the function and foreach loop:

     

     

         function outputModule($courseId, $courseName, $moduleId, $moduleName, $sessionData) 
            { 
            
                if(!count($sessionData)) 
                { 
                    return false; 
                } 
            
                $markTotal = 0; 
                $markGrade = 0; 
                $weightSession = 0;
                $courseTotal = 0;
                $grade = ""; 
                $sessionsHTML = ""; 
                
                foreach($sessionData as $session) 
                { 
            
                    $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; 
                    
                    $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
                    $weightSession  += ($session['SessionWeight']); 
                    $markGrade = round($markTotal /  $weightSession * 100); 
                         
                    if ($markGrade >= 70) 
                    { 
                        $grade = "A"; 
                    } 
            
                    else if ($markGrade >= 60 && $markGrade <= 69) 
                    { 
                        $grade = "B"; 
                    } 
            
                    else if ($markGrade >= 50 && $markGrade <= 59) 
                    { 
                        $grade = "C"; 
                    } 
            
                    else if ($markGrade >= 40 && $markGrade <= 49) 
                    { 
                        $grade = "D"; 
                    } 
            
                    else if ($markGrade >= 30 && $markGrade <= 39) 
                    { 
                        $grade = "E"; 
                    } 
            
                    else if ($markGrade >= 0 && $markGrade <= 29) 
                    { 
                        $grade = "F"; 
                    } 
            } 
            	
                echo "<p><br><strong>Course:</strong> {$courseId} - {$courseName} <strong>Course Mark:</strong></p><br>\n";
                $moduleHTML = "<p><strong>Module:</strong> {$moduleId} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$grade} </p>\n"; 
            
                return $moduleHTML . $sessionsHTML; 
            } 

  2. It is the same line. It came with two notices with the same notice on the same line. I did what you told me to do and it got rid of one notice but not the other. Below is the latest output on the browser:

     

     

    Notice: Undefined variable: sessionData in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 69

     

    Course: INFO101 - Bsc Information Communication Technology

     

     

    Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

     

    Session: AAB Session Mark: 72 Session Weight Contribution 20%

     

    Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

     

    Course: INFO101 - Bsc Information Communication Technology

     

     

    Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

     

    Session: AAD Session Mark: 61 Session Weight Contribution 50%

     

    Below is the current code: (It is same as code in first post except I added $courseId and $courseName in the "output .=" near the bottom)

     

     function outputModule($courseId, $courseName, $moduleId, $moduleName, $sessionData) 
        { 
        
            if(!count($sessionData)) 
            { 
                return false; 
            } 
        
            $markTotal = 0; 
            $markGrade = 0; 
            $weightSession = 0;
            $grade = ""; 
            $sessionsHTML = ""; 
        
            foreach($sessionData as $session) 
            { 
        
                $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; 
                $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
                $weightSession  += ($session['SessionWeight']); 
                $markGrade = round($markTotal /  $weightSession * 100); 
                     
                if ($markGrade >= 70) 
                { 
                    $grade = "A"; 
                } 
        
                else if ($markGrade >= 60 && $markGrade <= 69) 
                { 
                    $grade = "B"; 
                } 
        
                else if ($markGrade >= 50 && $markGrade <= 59) 
                { 
                    $grade = "C"; 
                } 
        
                else if ($markGrade >= 40 && $markGrade <= 49) 
                { 
                    $grade = "D"; 
                } 
        
                else if ($markGrade >= 30 && $markGrade <= 39) 
                { 
                    $grade = "E"; 
                } 
        
                else if ($markGrade >= 0 && $markGrade <= 29) 
                { 
                    $grade = "F"; 
                } 
        } 
        
        	$courseHTML = "<p><br><strong>Course:</strong> {$courseId} - {$courseName}</p><br>\n";
            $moduleHTML = "<p><strong>Module:</strong> {$moduleId} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$grade} </p>\n"; 
        
            return $courseHTML . $moduleHTML . $sessionsHTML; 
        } 
        
        $output = ""; 
        
        $studentId = false; 
        $courseId  = false; 
        $moduleId  = false; 
        
        while ($row = mysql_fetch_array($result)) 
        { 
        	
        	  if($courseId != $row['CourseId']) 
            { 
        
                //Course has changed 
                $courseName  = $row['CourseName'];
                $courseId = $row['CourseId']; 
        
                $output .= outputModule($courseId, $courseName);  
            }
        
            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($courseId, $courseName, $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($courseId, $courseName, $moduleId, $moduleName, $sessionsAry); 
        
        //Display the output 
        echo $output;

     

     

  3. Below is my code:

     

     

     

      function outputModule($courseId, $courseName, $moduleId, $moduleName, $sessionData) 
        { 
        
            if(!count($sessionData)) 
            { 
                return false; 
            } 
        
            $markTotal = 0; 
            $markGrade = 0; 
            $weightSession = 0;
            $grade = ""; 
            $sessionsHTML = ""; 
        
            foreach($sessionData as $session) 
            { 
        
                $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; 
                $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
                $weightSession  += ($session['SessionWeight']); 
                $markGrade = round($markTotal /  $weightSession * 100); 
                     
                if ($markGrade >= 70) 
                { 
                    $grade = "A"; 
                } 
        
                else if ($markGrade >= 60 && $markGrade <= 69) 
                { 
                    $grade = "B"; 
                } 
        
                else if ($markGrade >= 50 && $markGrade <= 59) 
                { 
                    $grade = "C"; 
                } 
        
                else if ($markGrade >= 40 && $markGrade <= 49) 
                { 
                    $grade = "D"; 
                } 
        
                else if ($markGrade >= 30 && $markGrade <= 39) 
                { 
                    $grade = "E"; 
                } 
        
                else if ($markGrade >= 0 && $markGrade <= 29) 
                { 
                    $grade = "F"; 
                } 
        } 
        
        	$courseHTML = "<p><br><strong>Course:</strong> {$courseId} - {$courseName}</p><br>\n";
            $moduleHTML = "<p><strong>Module:</strong> {$moduleId} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$grade} </p>\n"; 
        
            return $courseHTML . $moduleHTML . $sessionsHTML; 
        } 
        
        $output = ""; 
        
        $studentId = false; 
        $courseId  = false; 
        $moduleId  = false; 
        
        while ($row = mysql_fetch_array($result)) 
        { 
        	
        	  if($courseId != $row['CourseId']) 
            { 
        
                //Course has changed 
                $courseName  = $row['CourseName'];
                $courseId = $row['CourseId']; 
        
                $output .= outputModule($courseId, $courseName);  
            }
        
            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($courseId, $courseName, $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; 
    

    Below is the output:

     

     

        Notice: Undefined variable: sessionData in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 69

       

        Notice: Undefined variable: sessionData in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 69

       

        Course: INFO101 - Bsc Information Communication Technology

       

       

        Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

       

        Session: AAB Session Mark: 72 Session Weight Contribution 20%

       

        Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

    There is suppose to be another module with its own sessions below this but it does not show it. Also it is giving me notices that $SessionData is undefined. Why can it not find the variable $SessionData?

     

    Below is what it should of outputted:

     

    Course: INFO101 - Bsc Information Communication Technology Course Mark Grade

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

     

    Session: AAB Session Mark: 72 Session Weight Contribution 20%

     

    Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

     

    Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

     

    Session: AAD Session Mark: 61 Session Weight Contribution 50%

  4. Sorry this is a slight dulicate of a previous question I asked yesterday because I think I messed up when trying to ask this question and I think I made iu unclear for everbody

     

    Below is my output on the browser:

     

        Student: Kevin Smith (u0867587)

        Course: INFO101 - Bsc Information Communication Technology Course Mark 72 Grade

        Year: 3

       

       

        Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

       

        Session: AAB Session Mark: 72 Session Weight Contribution 20%

       

        Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

     

        Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

       

        Session: AAD Session Mark: 61 Session Weight Contribution 50%

     

        65

     

    Now where it says course mark above it says 72. This is incorrect as it should be 65 (The average between the module marks percentage should be 65 in the example above) but for some stange reason I can get the answer 65 (as it is displayed below the example). I have a variable called $courseMark and that does the calculation. Now if the $courseMark is echo outside the where loop, then it will equal 65 but if it is put in while loop where I want the variable to be displayed, then it adds up to 72. Why does it do this and how can I get the answer 65 in the while loop.

       

        Below is the relevant code (I havn't include all code as this could confuse you so I included code that is relevant for this question):

        $sessionMark = 0;
        $sessionWeight = 0;
        $courseMark = 0;
        
        $output = ""; 
        
        $studentId = false; 
        $courseId  = false; 
        $moduleId  = false; 
        
        while ($row = mysql_fetch_array($result)) 
        { 
        	
        	
        	$sessionMark += ($row['Mark'] / 100 * $row['SessionWeight']);
        	$sessionWeight  += ($row['SessionWeight']); 
            $courseMark = round($sessionMark /  $sessionWeight * 100);
        
                 
            if($courseId != $row['CourseId']) 
            { 
        
                //Course has changed 
                $courseId = $row['CourseId']; 
        
                $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong> $courseMark <strong>Grade</strong>  <br><strong>Year:</strong> {$row['Year']}</p>\n"; 
        
            } 
        
        
        
        //Display the output 
        echo $output; 
    echo $courseMark;

     

  5. Below is my output on the browser:

     

        Student: Kevin Smith (u0867587)

        Course: INFO101 - Bsc Information Communication Technology Course Mark 70 Grade

        Year: 3

       

       

        Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

       

        Session: AAB Session Mark: 72 Session Weight Contribution 20%

       

        Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

     

        Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

       

        Session: AAD Session Mark: 61 Session Weight Contribution 50%

     

    Now where it says course mark above it says 70. This is incorrect as it should be 65 (The average between the module marks percentage should be 65 in the example above) but for some stange reason I can get the answer 65. I have a variable called $courseMark and that does the calculation. Now if the $courseMark is echo outside the where loop, then it will equal 65 but if it is put in while loop where I want the variable to be displayed, then it adds up to 70. Why does it do this.

       

        Below is the code:

     

        $sessionMark = 0;
        $sessionWeight = 0;
        $courseMark = 0;
        
        $output = ""; 
        
        $studentId = false; 
        $courseId  = false; 
        $moduleId  = false; 
        
        while ($row = mysql_fetch_array($result)) 
        { 
        	
        	
        	$sessionMark += round($row['Mark'] / 100 * $row['SessionWeight']);
        	$sessionWeight  += ($row['SessionWeight']); 
            $courseMark = ($sessionMark /  $sessionWeight * 100);
        
              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']} <strong>Course Mark</strong>" round($courseMark) "<strong>Grade</strong>  <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; 

     

    I think the problem is that it is outputting the answer of the calculation only for the first session mark. How in the while loop can I do it so it doesn't display it for the first mark only but for all the session marks so that it ends up showing the correct answer 65 and not 72?

  6. I am sorry for this but I am a database specialist, I have to do php because there is no one else. I have only done php once and that was two years ago following a bacic workbook. But I do appreciate the help you have given me. To be very honest this is the very last thing I need to do and then this document is done and the document is finished.

     

    What I wanted to do is add all of the module marks ($markGrade) and then divide it by the number of modules ($totalLoops) so that I get the Student's course mark. Because I need to use the calculation in foreach loop, I have to move the course details from the while loop and put it in the for each loop so I tried to do it as the same as how you did the module details where you managed to get all sessions per module. I wanted to get all modules per course. It works in the while loop when you gave me the code but because I need to move the course details into the foreach loop, I tried to do this below but it ends up coming up with notice saying undefined variable $SessionData (I know its a brace in wrong place) but even if I sort this out it will not display anything.

     

    Below is what I tried but it didn't work:

     

    <?php
         
         if($num ==0){
        echo "<p>Sorry, No Records were found from this Search</p>";}
        else{
        
      function outputModule($courseID, $courseName, $moduleID, $moduleName, $sessionData)    
      
      {        
      
      if(!count($sessionData)) { return false; }        
      
      $markTotal = 0;        
      $markGrade = 0;
      $markGradeSum = 0;
      $totalLoops = 0;
      $weightSession = 0;
      $courseTotal = 0;
      $grade = "";
      $sessionsHTML = "";
      $courseHTML = "";
      
      foreach($sessionData as $session)        {           
    	  
    	   $courseHTML = "<p><br><strong>Course:</strong> {$courseID} - {$courseName} Mark: {$courseTotal}</p>/n";       
    	  
    	   $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n";            
    	   
    	    
    	   $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
    	   $weightSession  += ($session['SessionWeight']);  
    	   $markGrade = round($markTotal /  $weightSession * 100);
    	   $totalLoops++;
    	   $markGradeSum += $markGrade;
    	   $courseTotal = ($markGradeSum / $totalLoops);
    	   
    if ($markGrade >= 70){
    	$grade = "A";}      
    
    else if ($markGrade >= 60 && $markGrade <= 69){
    	$grade = "B";}
    
    else if ($markGrade >= 50 && $markGrade <= 59){
    	$grade = "C";}
    
    else if ($markGrade >= 40 && $markGrade <= 49){
    	$grade = "D";}
    
    else if ($markGrade >= 30 && $markGrade <= 39){
    	$grade = "E";}
    
    else if ($markGrade >= 0 && $markGrade <= 29){
    	$grade = "F";}
    	   
    	   }        
    	   
    	   $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$grade} </p>\n";       
    	   
    	    return $sessionHTML . $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'])        {            
    
              
    				 if(isset($modulessAry))           
    
    				  {              
    					  
    					                 
    					    $output .= outputModule($courseId, $courseName, $modulesAry);            }            
    					    
    					               
    					    
    					     $modulesAry = array();            
    					     $courseId    = $row['CourseId'];         
    					     $courseName  = $row['CourseName'];        }        
    					     
    					           
    					     
    					     $modulesAry[] = array('CourseId'=>$row['CourseId'], 'CourseName'=>$row['CourseName']);    
    					     
    					     						     						 					          
    			        
    			 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;
    
          }
      }
        ?>

     

    Below is what I want for the result output:

     

    Student Username: 'u0867587'

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology      Course Mark 65

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications Module Mark: 41 Mark Percentage: 68 Grade: B

     

    Session: AAB Session Mark: 72 Session Weight Contribution 20%

     

    Session: AAE Session Mark: 67 Session Weight Contribution 40%

     

     

    Module: CHI2513 - Systems Strategy Module Mark: 31 Mark Percentage: 62 Grade: B

     

    Session: AAD Session Mark: 61 Session Weight Contribution 50%

     

     

    Thank you and sorry for all the answers I have asked from you and others.

  7. Hi,

     

    Look at this code below:

     

    <?php function outputModule($moduleID, $moduleName, $sessionData) 
    { 
    
        if(!count($sessionData)) 
        { 
            return false; 
        } 
    
        $markTotal = 0; 
        $markGrade = 0; 
        $weightSession = 0; 
        $grade = ""; 
        $sessionsHTML = ""; 
    
        foreach($sessionData as $session) 
        { 
    
            $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n"; 
            $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
            $weightSession  += ($session['SessionWeight']); 
            $markGrade = round($markTotal /  $weightSession * 100); 
                 
            if ($markGrade >= 70) 
            { 
                $grade = "A"; 
            } 
    
            else if ($markGrade >= 60 && $markGrade <= 69) 
            { 
                $grade = "B"; 
            } 
    
            else if ($markGrade >= 50 && $markGrade <= 59) 
            { 
                $grade = "C"; 
            } 
    
            else if ($markGrade >= 40 && $markGrade <= 49) 
            { 
                $grade = "D"; 
            } 
    
            else if ($markGrade >= 30 && $markGrade <= 39) 
            { 
                $grade = "E"; 
            } 
    
            else if ($markGrade >= 0 && $markGrade <= 29) 
            { 
                $grade = "F"; 
            } 
                  
    
        $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$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']} <strong>Course Mark</strong> <strong>Grade</strong>  <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; 
    
    }
          }
      }
        ?>

     

    This code allallows me to make calculations and display a student's course and linked with it the course the modules in the course and linked with modules are all the sessions. It is able to display what marks each student have got for each module and session.

     

    Now look at code below, it is able to display modules and in those modules the sessions that link to those modules:

     

     

    <?php 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']); 
             
    }
    

    What I want to know is how can I do something similar for course so that it picks out the right modules depending on the course it displays. There maybe some code that needs to be added in the function.

  8. Hi,

     

    I am not very good with php but this code was kindly given to me by mdjamato, except I added a variable $markGradeSum to add all the $markGrade. Problem is that I will get notice saying undefined variable $markGradeSum because the $markGradeSum is in the foreach loop which it needs to be in for the right calculation but where I want to output the variable is in the while loop in this line:

     

     $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <strong>Course Mark</strong> <strong>Grade</strong>  <br><strong>Year:</strong> {$row['Year']  $markGradeSum}</p>\n"; 

     

    Below is whole code:

     

     <?php
         
         if($num ==0){
        echo "<p>Sorry, No Records were found from this Search</p>";}
        else{
        
      function outputModule($moduleID, $moduleName, $sessionData)    
      
      {        
      
      if(!count($sessionData)) { return false; }        
      
      $markTotal = 0;        
      $markGrade = 0;
      $weightSession = 0;
      $markGradeSum = 0;
      $grade = "";
      $sessionsHTML = "";
      $courseHTML = "";
      
      foreach($sessionData as $session)        {           
    	  
    	   $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <strong>Session Mark:</strong> {$session['Mark']}</strong> <strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n";            
    	   $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
    	   $weightSession  += ($session['SessionWeight']);  
    	   $markGrade = round($markTotal /  $weightSession * 100);
    	   $markGradeSum = round($markGrade);
    	   
    if ($markGrade >= 70){
    	$grade = "A";}      
    
    else if ($markGrade >= 60 && $markGrade <= 69){
    	$grade = "B";}
    
    else if ($markGrade >= 50 && $markGrade <= 59){
    	$grade = "C";}
    
    else if ($markGrade >= 40 && $markGrade <= 49){
    	$grade = "D";}
    
    else if ($markGrade >= 30 && $markGrade <= 39){
    	$grade = "E";}
    
    else if ($markGrade >= 0 && $markGrade <= 29){
    	$grade = "F";}
    	   
    	   }        
    	   
    	   $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <strong>Module Mark:</strong> {$markTotal} <strong>Mark Percentage:</strong> {$markGrade} <strong>Grade:</strong> {$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']} <strong>Course Mark</strong> <strong>Grade</strong>  <br><strong>Year:</strong> {$row['Year']  $markGradeSum}</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;
    
          }
      }
        ?> 

     

     

    How can I retrieve the variable so it doesn't come up with the notice but be able to display $markGradeSum to the places I want them in (one in foreach loop for calculation and other in while loop for output).

     

    Thank You

  9. This code was given to me by mjdamato to help display a student and the course that student has take and within that the modules in the course and the sessions in course including module mark and grade and student's session marks and grades. I am very weak on php code as I have only done it once and that was following a php workbook 2 years ago. I am more of a database specialist. Below is the code given to me and you can also download the code from the attachment:

     

    <?php
    
    function outputModule($moduleID, $moduleName, $sessionData)    
      
      {        
      
      if(!count($sessionData)) { return false; }        
      
      $markTotal = 0;        
      $markGrade = 0;
      $weightSession = 0;
      $grade = "";
      $sessionsHTML = "";
      
      foreach($sessionData as $session)        {           
    	  
    	   $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} <br><strong>Session Mark:</strong> {$session['Mark']}</strong> <br><strong>Session Weight Contribution</strong> {$session['SessionWeight']}%</p>\n";            
    	   $markTotal += round($session['Mark'] / 100 * $session['SessionWeight']); 
    	   $weightSession  += ($session['SessionWeight']);  
    	   $markGrade = round($markTotal /  $weightSession * 100);
    	   
    if ($markGrade >= 70){
    	$grade = "A";}      
    
    else if ($markGrade >= 60 && $markGrade <= 69){
    	$grade = "B";}
    
    else if ($markGrade >= 50 && $markGrade <= 59){
    	$grade = "C";}
    
    else if ($markGrade >= 40 && $markGrade <= 49){
    	$grade = "D";}
    
    else if ($markGrade >= 30 && $markGrade <= 39){
    	$grade = "E";}
    
    else if ($markGrade >= 0 && $markGrade <= 29){
    	$grade = "F";}
    	   
    	   }        
    	   
    	   $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} <br><strong>Module Mark:</strong> {$markTotal} <br><strong>Mark Percentage:</strong> {$markGrade} <br><strong>Grade:</strong> {$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']} <strong>Course Mark</strong> <strong>Grade</strong>  <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;
    
          }
      }
        ?>

     

    Below the what this code outputs:

     

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology      Course Mark

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications        Module Mark: 41          Mark Percentage: 68            Grade: B

     

    Session: AAB            Session Mark: 72              Session Weight Contribution 20%

     

    Session: AAE            Session Mark: 67              Session Weight Contribution 40%

     

     

    Module: CHI2513 - Systems Strategy            Module Mark: 31          Mark Percentage: 62            Grade: B

     

    Session: AAD              Session Mark: 61            Session Weight Contribution 50%

     

     

    If you look above it shows that there is nothing in the Course Mark: section, what Course Mark is suppose to do is total up all the module mark percentages and then divide it by the number of modules. So the calculation will be adding up all the

    $markGrade

    and dividing it by count

    $ModuleID

    . In examle above it will be 68 (mark percentage for 1st module) + 62 (mark percentage for 2nd  module) / 2 (number of modules in the course). So the Course Mark should equal 65. 

     

    The problem is that all of the calculations are in the foreach loop but where the course details and where the course marks are going to be placed are in the while loop. So the problem is that if the total Course Mark (lets say we call in $totalCourse) is displayed in the while loop it will provide an undifined index as the calculation will be placed with the other calculations in the foreach loop which is outside the while loop, if I do the calculation with in the while loop, it will only choose the 1st module mark percentage and divdie it by the first module only, this is obviously incorrect as it sohuld try and do this for all modules hence why my calculations are in the foreach loop which does this.

     

    So how will change the code so that the course details can go from the while loop and be placed in the foreach loop so then I can include the calculation in the foreach loop.

     

    Thank You and hopefully you understand it, just read it very carefully to understand it, it is very simple what I want to achieve but I do not know how to do it.

     

    [attachment deleted by admin]

  10. Hi, My results were fine when displaying them on the browser but then  want to output student's grades depending on what mark they have got. I have put an if statement for this:

     

       if ($markGrade >= 70){
       $grade = "A";} 

     

    But when I put the above if statement in the code then the browser outputs this:

     

    Your Search:

     

    Student Username: 'u0867587'

     

    Notice: Undefined variable: sessionData in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 79

     

    Notice: Undefined variable: moduleID in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91

     

    Notice: Undefined variable: moduleName in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91

     

    Notice: Undefined variable: markTotal in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91

     

    Notice: Undefined variable: markGrade in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91

     

    Notice: Undefined variable: grade in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91

     

    Notice: Undefined variable: sessionsHTML in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 93

     

     

    Why is it not recognisiong any variables?

     

    The code is below and in the attached file.

    <?php
          if (isset($_POST['submit'])) {
    
          $query = "
              SELECT st.CourseId, c.CourseName, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname,
              s.ModuleId, m.ModuleName, m.Credits, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade
              FROM Course c
              INNER JOIN Student st ON c.CourseId = st.CourseId
              JOIN Grade_Report gr ON st.StudentId = gr.StudentId
              JOIN Session s ON gr.SessionId = s.SessionId
              JOIN Module m ON s.ModuleId = m.ModuleId
              WHERE
              (st.StudentUsername = '".mysql_real_escape_string($studentid)."')
              ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId
              ";
    
            $num = mysql_num_rows($result = mysql_query($query));
            mysql_close();
    
        ?>
    
          <p>
          Your Search:
          </p>
          <p>
          <strong>Student Username:</strong> <?php echo "'$studentid'"; ?><br/>
        </p>
         <?php
         
         if($num ==0){
        echo "<p>Sorry, No Records were found from this Search</p>";}
        else{
        
      function outputModule($moduleID, $moduleName, $sessionData)    
      
      {        
      
      if(!count($sessionData)) { return false; }        
      
      $markTotal = 0;        
      $markGrade = 0;
      $weightSession = 0;
      $grade = "";
      $sessionsHTML = '';  
      
    };      
      
      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);   
    	   
    	   if ($markGrade >= 70){
    		   $grade = "A";} 
    	   
    	   }        
    	   
    	   $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;
    
          }
          
        ?>

     

     

     

     

     

    [attachment deleted by admin]

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

  12. My case statement is not working. What happened is that two students got a $markgrade of 61 and 67. So they both should get grade B but instead they both get Grade A. 1 student got 55 which should be grade C but gets grade A. why is it not following the switch statement?

     

        function outputModule($moduleID, $moduleName, $sessionData)    
          
          {        
        	  
        	  if(!count($sessionData)) { return false; }  
        
        
        $markTotal = 0;        
            	  $markGrade = 0;
            	  $weightSession = 0;
            	  $grade = "";
            	  $sessionsHTML = '';  
            	  
            	  switch($grade){
            	case ($markGrade >=70):
            	$grade = 'A';
            	break;
            	case ($markGrade >=60 && $markGrade <=69):
            	$grade = 'B';
            	break;
            	case ($markGrade >=50 && $markGrade <=59):
            	$grade = 'C';
            	break;
            	case ($markGrade >=40 && $markGrade <=49):
            	$grade = 'D';
            	break;
            	case ($markGrade >=30 && $markGrade <=39):
            	$grade = 'E';
            	break;
            	case ($markGrade >=0 && $markGrade <=29):
            	$grade = 'F';
            	break;
            };      
            	  
            	  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;    } 

  13. This is a bit of a puzzle. Look at the sum and result below:

     

     $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']);

     

     

    Result on Browser with explanation to help you:

     

    Module: CHI2550 - Modern Database Applications    35% (this is $markTotal)  ... This is where I want add the total mark for 100%

     

    Session: AAB        100% (this is $session['Mark'])      10% (this is  $session['SessionWeight'])

     

    Session: AAE      50% (this is $session['Mark'])    50%  (this is  $session['SessionWeight'])

     

    All percentage marks above are just add ons.

     

     

    As you can see the answer to the calculation above is right, the answer is 35 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage.

     

    But I want to include a total mark where except it is out of the total session percentage (60% for above example as one Session is 40% and the other is 20%), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. The total mark out of 100% of the above example should be 65%, but how do I achieve this in my calculation. It is not as simple as dividing the $session['Mark'] because one session is worth more than the other. So the above example will have 2 marks: one mark out of total percentage of the Sessions which for the above example is 35% and second mark is out of the full 100% of the module which is 65%.

     

    Thank you and any help is much appreciated

  14. This is a bit of a puzzle. Look at the sum and result below:

     

     $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']);

     

    Result on Browser

     

    Module: CHI2550 - Modern Database Applications    41.2 (this is $markTotal)

     

    Session: AAB        72(this is $session['Mark'])      20% (this is  $session['SessionWeight'])  (The percentage signs are just add ons)

     

    Session: AAE        67(this is $session['Mark'])      40%  (this is  $session['SessionWeight'])

     

     

    As you can see the answer to the calculation above is right, the answer is 41 .2 as it adds up the two session marks, divide by 100 and then times it by the total amount of the percentage.

     

    But I want to include a total mark where except it is out of the total session percentage (60% for above example), it is out of a 100% but I can not work as simple as that as in above example one session is worth more than other. I have worked out that the answer for the total mark of the above example out of 100% should be 69, but how do I achieve this in my calculation.

     

    Thank you and any help is much appreciated :)

     

    So how

  15. That has worked perfectly cheers. I did spot the .= problem before because it cam up with an error message on unexpected T_VARIABLE for that line but it must of been sometihng else you have changed to get it working.  Thank you very much, how you know a lot about php is beyond me, I am more of a database specialist than a programming specialist but you are the genius. You have helped me twice now and I really do appreciate it. Thank you again  :):D

  16. When I use the code you have given me this is what it is outputting:

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

     

    Module: CHI2550 - Modern Database Applications 72

     

    Session: AAB 72

     

     

    Module: CHI2513 - Systems Strategy 61

     

    Session: AAD 61

     

    I can't understand what it is doing. Do you have any idea?

  17. Hi, thanks for your answer but it has not quite worked,, it adds up the sessions very well for each module but it shows each session and module seperatly rather than together as I wanted it. e.g. If a module in a course has 2 sessions, it will show both sessions under that module but instead the code you have given me splits up the session and module so it will show the name of the module and one session and then it will show the module name again and then show the other session beneath that but I don't want that. Thanks for your attempt though much apprciated, if you have another idea then can you please share it with me or be able to edit the code you have game me?

  18. I have a calculation issue in my php. I want to add up all of the session marks ($row['Mark']} for each module and display the answer for each module at the end of each module name.  Below is my code:

     

       $output = "";
        $studentId  = false;
        $courseId  = false;
        $moduleId  = false;
        
            //BELOW IS THE CALCULATION IN PHP
            
            $moduletotal = 0;
            
            while ($row = mysql_fetch_array($result)){    
            	
                $moduletotal += $row['Mark'];
                
                $modulemark = (int)($moduletotal);
        
        //BELOW IS HOW PHP WILL DISPLAY THE RESULT
         ($modulemark is at the end of the 3rd (last) if statement)
                  
        	if($studentId != $row['StudentUsername'])  {        
        			
        		$studentId = $row['StudentUsername'];        
        		$output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})";   
        			
        	   }    
        	   
        	   	if($courseId != $row['CourseId']) {    
        		
        		$courseId = $row['CourseId'];        		
        		$output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>";    
        		
        		}    
        			 
        	if($moduleId != $row['ModuleId'])  {        
        				 
        	   $moduleId = $row['ModuleId'];        
        	   $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} $modulemark</p>";   
        				 
        	  }  
        	    
        	   $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']}</p>";
        	
        
            			   
              }				 
          
        	echo $output;    }

     

     

    BELOW IS THE RESULT IT SHOWS ON THE BROWSER:

     

        Student: Mayur Patel (u0867587)

        Course: INFO101 - Bsc Information Communication Technology 

        Year: 3

       

       

        Module: CHI2550 - Modern Database Applications 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139)

       

        Session: AAB 72

       

        Session: AAE 67

       

        Module: CHI2513 - Systems Strategy 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module)

       

        Session: AAD 61

     

     

    It is obvious that I am not resetting $moduletotal to 0 when the module changes . I need to detect when to stop summing, emit and store the result, and then reset the counter. But I do not know to do this using php, can somebody please help me and provide a smaple code for this? Thank You

     

     

     

     

     

  19. That didn't work Joel, if I do that it does not display any results. Thats why I prefer doing my calculations using php rather than SQL functions. By the way how do I delete this post because I have a similar post which explains the question a bit more better than this one?

  20. Hi,

     

    I have a calculation issue in my php. Below is my code:

     

    $output = "";
    $studentId  = false;
    $courseId  = false;
    $moduleId  = false;
            
    while ($row = mysql_fetch_array($result)){    
    
            $moduletotal += $row['Mark'];
            
            $modulemark = (int)($moduletotal);
              
    //Above here is the calculation for add in the Marks of all the sessions
    
    //Below is the code of the display of the query output
    
    
    if($studentId != $row['StudentUsername'])  {        
    
    	$studentId = $row['StudentUsername'];        
    	$output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})";   
    
       }    
       
       	if($courseId != $row['CourseId']) {    
    
    	$courseId = $row['CourseId'];        		
    	$output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>";    
    
    	}    
    
    if($moduleId != $row['ModuleId'])  {        
    
       $moduleId = $row['ModuleId'];        
       $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} $modulemark</p>";   
    
      }  
        
       $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']}</p>";
    			   
      }
    

     

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology 

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139)

     

    Session: AAB 72

     

    Session: AAE 67

     

    Module: CHI2513 - Systems Strategy 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module)

     

    Session: AAD 61

     

     

     

    SO WHAT MY QUESTION IS THAT HOW CAN I FIND THE TOTAL OF EACH MODULE MARK WHICH THE VARIABLE $modulemark = (int)($moduletotal); IS TRYING TO DO BY ADDING UP ALL THE SESSIONS MARKS WITHIN EACH MODULE.

     

    I HAVE TRIED USING SUM(gr.Mark) in the query and using GROUP BY SessionId, ModuleId, StudentUsername, and CourseId but it ends up not being able to display any records. That is why I want to do the calculation using php rather than SQL.

     

    BELOW IS THE QUERY IF YOU WANT TO SEE IT:

     

    $query = "
              SELECT st.CourseId, c.CourseName, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname,
              s.ModuleId, m.ModuleName, m.Credits, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade
              FROM Course c
              INNER JOIN Student st ON c.CourseId = st.CourseId
              JOIN Grade_Report gr ON st.StudentId = gr.StudentId
              JOIN Session s ON gr.SessionId = s.SessionId
              JOIN Module m ON s.ModuleId = m.ModuleId
              WHERE
              (st.StudentUsername = '".mysql_real_escape_string($studentid)."')
              ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId
              ";

  21. Hi,

     

    I have a calculation issue in my php. Below is my code:

     

     

     

    $

    moduletotal = 0;
    $modulecount = 0;
    $sessionweight = 0;
            
    while ($row = mysql_fetch_array($result)){    
    
            $moduletotal += $row['Mark'];      
      
            $modulemark = (int)($moduletotal);  // Here and above is the calculation which is simply adding the total number of marks
    
    
    // Below is the code that displays my results. The variable of the calculation is shown at the end of the last if statement (3rd one down)
    
    $output = "";
    $studentId  = false;
    $courseId  = false;
    $moduleId  = false;
              
    if($studentId != $row['StudentUsername'])  {        
    
    	$studentId = $row['StudentUsername'];        
    	$output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})";   
    
       }    
       
      if($courseId != $row['CourseId']) {    
    
    	$courseId = $row['CourseId'];        		
    	$output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>";    
    
    	}    
    
    if($moduleId != $row['ModuleId'])  {        
    
       $moduleId = $row['ModuleId'];        
       $output .= "<p><br><strong>Module:</strong> {$row['ModuleId']} - {$row['ModuleName']} {$row['Credits']} $modulemark</p>";   
    
      }  
        
       $output .= "<p><strong>Session:</strong> {$row['SessionId']} {$row['Mark']} {$row['Grade']} {$row['SessionWeight']}%</p>";
    			   
      }
    
      
    echo $output;
    
          ?>

    The Results look like this at the moment (The answer the calculation is next to each Module):

     

    Student: Mayur Patel (u0867587)

    Course: INFO101 - Bsc Information Communication Technology 

    Year: 3

     

     

    Module: CHI2550 - Modern Database Applications 20 72 (72 is the answer to the calculation for the first module but this is incorrect at it should also add the 67 and thus become 139)

     

    Session: AAB 72 A 20%

     

    Session: AAE 67 B 40%

     

     

    Module: CHI2513 - Systems Strategy 20 200 (200 is the answer to the calculation for this module but this is incorrect it should be only 61. But what it has done is that it has added the 72 and 67 from the first module and added it with the 61 in this module)

     

    Session: AAD 61 B 50%

     

     

     

    SO WHAT MY QUESTION IS HOW CAN I GET THE CALCULATION SO THAT IT ONLY ADDS UP EACH SESSION MARKS THAT BELONGS TO A MODULE ONLY? IN THE EXAMPLE ABOVE IT SHOULD ONLY ADD THE MARKS FOR SESSION AAB AND AAE IN THE MODERN DATABASE APPLICATIONS MODULE AND THEN WHEN IT GETS TO THE NEXT MODULE WHICH IS SYSTEMS STRATEGY, THE MARKS FOR THAT MODULE SHOULD START AGAIN AND ADD ON THE MARKS FOR THE SESSION AAD IN THAT MODULE. HOPEFULLY YOU UNDERSTAND AND THANK YOU

     

    Below is the query if you want to look at it:

     

     $query = "
              SELECT c.CourseName,  
    st.CourseId, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname,
    s.ModuleId, s.SessionId, s.SessionWeight, 
    gr.Mark, gr.Grade
    m.ModuleName, m.Credits,
              FROM Course c
              INNER JOIN Student st ON c.CourseId = st.CourseId
              JOIN Grade_Report gr ON st.StudentId = gr.StudentId
              JOIN Session s ON gr.SessionId = s.SessionId
              JOIN Module m ON s.ModuleId = m.ModuleId
              WHERE
              (st.StudentUsername = '".mysql_real_escape_string($studentid)."')
              ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId
              ";

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