我正在尝试使用PHP和MySQL数据库创建学生考试成绩系统。但是,我遇到了两个问题:
首先,输入CA1,CA2和考试的分数时,仅显示考试分数。似乎没有为CA1和CA2输入任何内容,它们也未显示在我的数据库中。
第二,如何自动计算CA1,CA2和考试的分数以获得总成绩?
这是我的代码
<div class="row">
<div class="col-md-2"></div>
<div class="col-md-8">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">
<?php echo get_phrase('Enter Subject Scores') ?>
</h3>
</div>
<div class="panel-body">
<?php echo form_open(site_url('admin/marks_update/'.$exam_id.'/'.$class_id.'/'.$section_id.'/'.$subject_id));?>
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>
<?php echo get_phrase('id');?>
</th>
<th>
<?php echo get_phrase('name');?>
</th>
<th>
<?php echo get_phrase('CA1');?>
</th>
<th>
<?php echo get_phrase('CA2');?>
</th>
<th>
<?php echo get_phrase('Exam');?>
</th>
</tr>
</thead>
<tbody>
<?php
$count = 1;
$marks_of_students = $this->db->get_where('mark' , array(
'class_id' => $class_id,
'section_id' => $section_id ,
'year' => $running_year,
'subject_id' => $subject_id,
'exam_id' => $exam_id
))->result_array();
foreach($marks_of_students as $row):
?>
<tr>
<td>
<?php echo $count++;?>
</td>
<td>
<?php echo $this->db->get_where('student',array('student_id'=>$row['student_id']))->row()->student_code;?>
</td>
<td>
<?php echo $this->db->get_where('student' , array('student_id' => $row['student_id']))->row()->name;?>
</td>
<td>
<input type="text" class="form-control" name="ca1_<?php echo $row['mark_id'];?>" value="<?php echo $row['ca1'];?>">
</td>
<td>
<input type="text" class="form-control" name="ca2_<?php echo $row['mark_id'];?>" value="<?php echo $row['ca2'];?>">
</td>
<td>
<input type="text" class="form-control" name="marks_obtained_<?php echo $row['mark_id'];?>" value="<?php echo $row['mark_obtained'];?>">
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
这就是正在显示的
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary panel-shadow" data-collapsed="0">
<div class="panel-heading">
<div class="panel-title">
<?php echo $row2['name'];?>
</div>
</div>
<div class="panel-body">
<div class="col-md-6">
<table class="table table-bordered">
<thead>
<tr>
<td style="text-align: center;">Subject</td>
<td style="text-align: center;">CA1</td>
<td style="text-align: center;">CA2</td>
<td style="text-align: center;">Exam</td>
<td style="text-align: center;">Highest Score</td>
<td style="text-align: center;">Grade</td>
</tr>
</thead>
<tbody>
<?php
$total_marks = 0;
$total_grade_point = 0;
$subjects = $this->db->get_where('subject' , array(
'class_id' => $class_id , 'year' => $running_year
))->result_array();
foreach ($subjects as $row3):
?>
<tr>
<td style="text-align: center;">
<?php echo $row3['name'];?>
</td>
<td style="text-align: center;">
<?php
$obtained_mark_query = $this->db->get_where('mark' , array(
'subject_id' => $row3['subject_id'],
'exam_id' => $row2['exam_id'],
'class_id' => $class_id,
'student_id' => $student_id ,
'year' => $running_year));
if ( $obtained_mark_query->num_rows() > 0) {
$marks = $obtained_mark_query->result_array();
foreach ($marks as $row4) {
echo $row4['CA1'];
$total_marks += $row4['mark_obtained'];
}
}
?>
</td>
<td style="text-align: center;">
<?php
$obtained_mark_query = $this->db->get_where('mark' , array(
'subject_id' => $row3['subject_id'],
'exam_id' => $row2['exam_id'],
'class_id' => $class_id,
'student_id' => $student_id ,
'year' => $running_year));
if ( $obtained_mark_query->num_rows() > 0) {
$marks = $obtained_mark_query->result_array();
foreach ($marks as $row4) {
echo $row4['CA2'];
$total_marks += $row4['mark_obtained'];
}
}
?>
</td>
<td style="text-align: center;">
<?php
$obtained_mark_query = $this->db->get_where('mark' , array(
'subject_id' => $row3['subject_id'],
'exam_id' => $row2['exam_id'],
'class_id' => $class_id,
'student_id' => $student_id ,
'year' => $running_year));
if ( $obtained_mark_query->num_rows() > 0) {
$marks = $obtained_mark_query->result_array();
foreach ($marks as $row4) {
echo $row4['mark_obtained'];
$total_marks += $row4['mark_obtained'];
}
}
?>
</td>
<td style="text-align: center;">
<?php
$highest_mark = $this->crud_model->get_highest_marks( $row2['exam_id'] , $class_id , $row3['subject_id'] );
echo $highest_mark;
?>
</td>
<td style="text-align: center;">
<?php
if($obtained_mark_query->num_rows() > 0) {
if ($row4['mark_obtained'] >= 0 || $row4['mark_obtained'] != '') {
$grade = $this->crud_model->get_grade($row4['mark_obtained']);
echo $grade['name'];
$total_grade_point += $grade['grade_point'];
}
}
?>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
我怀疑这也是一个数据库问题,但我真的不知道从这里出发。
为此,我的数据库表名为“标记”,其中插入了以下内容
mark_id,student_id,subject_id,class_id,section_id,exam_id,ca1,ca2,mark_obtained,mark_total,评论,年份