patternphpMinor
Student marks report
Viewed 0 times
reportmarksstudent
Problem
I want to display a table similar to this:
This table is generated from three tables depending on the student ID:
I don't want the table to depend on fixed values. For example, I should be able to add a subject or exam in the database and see the changes reflected in the table without touching the code. Any suggestions?
This table is generated from three tables depending on the student ID:
I don't want the table to depend on fixed values. For example, I should be able to add a subject or exam in the database and see the changes reflected in the table without touching the code. Any suggestions?
-';
}else{
echo ' '.$sjn[$d].'';
}
///////// display exams in table head tds
for ($p=1;$p '.$exn[$p].'';
}else{
?>
Solution
////////////////Select the student marks and put it in array with subject id and exam id
$result = mysql_query("SELECT * FROM stu_marks");
while ($row= mysql_fetch_array($result)){
$arr[$row['Subj_ID']][$row['Exam_ID']]=$row['Grade'];
}I don't fully understand why you are pulling data out of an array to put it back into an array. You should consider writing better, more specific sql queries so that the result of the individual SQl query is as close to what you want your table to look like as possible. From there, you can then loop through the already made (via mysql_fetch_array) result and reduce the amount of redundancy.
Also, use PDO, don't use or die (probably not ready for these two yet) and for the love of god, NAME YOUR VARIABLES DESCRIPTIVELY. I can barely tell whats going on and it's not in any way complicated.
Code Snippets
////////////////Select the student marks and put it in array with subject id and exam id
$result = mysql_query("SELECT * FROM stu_marks");
while ($row= mysql_fetch_array($result)){
$arr[$row['Subj_ID']][$row['Exam_ID']]=$row['Grade'];
}Context
StackExchange Code Review Q#13401, answer score: 5
Revisions (0)
No revisions yet.