Jump to content

Not recognizing variables


u0867587

Recommended Posts

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]

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.