I have a minor problem where my code store the value and can run as usual, but when I want to display it again, the value won't display and the error is:
Notice: Undefined variable: result_c in C:\xampp\htdocs\eAttendance\*******.***php on line 91
Which is:
<td><?php echo $GLOBALS['result_c'] ?></td>
My question is:
- Why I cant call back my variable inside
$result_c? - What should I do? do you have any ideas?
- What is the appropriate method to make this coding successful?
I made this code because I wanted to calculate all the values in array stored inside $result_c to become average percentage of attendance.
<table >
<tr>
<td>Matrix Card</td>
<td>Percent</td>
</tr>
<?php
$sbj = $_GET['sbj'];
$cls = $_GET['cls'];
$sql = mysql_query ("SELECT * FROM stu_course where class = '$cls' and subject_code = '$sbj'");
$a = 0;
while ($row = mysql_fetch_assoc($sql)){
?>
<tr>
<?php
$result1[] = $row['login_id'];
$sql1 = mysql_query("Select * from attendance where id_student = '$result1[$a]' and subject_code = '$sbj'") or die('Query failed. ' . mysql_error());
$b = 0;
while($row1 = mysql_fetch_assoc($sql1))
{
$popo = 1;
$result_array[] = $row1['credit_hour'];
$add = $result_array[$b];
$result_c = $result_c + $add;
}?>
<td><?php echo $result1[$a];?></td>
<td><?php echo $GLOBALS['result_c'] ?></td>
<?php
$a++;
}
?>
</tr>
</table>
$result_cvariable, you are using$GLOBALSalthough$result_cis in your current instead of global scope, you are always setting the$popovariable to 1 without ever using it (or if you removed that portion of code then you could simply set the variable outside of the loop. To get back to your initial question, simply use$result_crather than$GLOBALS['result_c'].