Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有一种方法可以只使用PHP获得最高和最低分数?_Php_Codeigniter - Fatal编程技术网

有没有一种方法可以只使用PHP获得最高和最低分数?

有没有一种方法可以只使用PHP获得最高和最低分数?,php,codeigniter,Php,Codeigniter,我有一个班级学生的分数表。所有科目的测验和考试成绩都在那里整理和记录 CREATE TABLE `scores_primary` ( `id` int(20) NOT NULL, `student_id` int(11) DEFAULT NULL, `class_id` int(5) DEFAULT NULL, `section_id` int(5) DEFAULT NULL, `subject_id` int(11) DEFAULT NULL, `session_id`

我有一个班级学生的分数表。所有科目的测验和考试成绩都在那里整理和记录

CREATE TABLE `scores_primary` (
  `id` int(20) NOT NULL,
  `student_id` int(11) DEFAULT NULL,
  `class_id` int(5) DEFAULT NULL,
  `section_id` int(5) DEFAULT NULL,
  `subject_id` int(11) DEFAULT NULL,
  `session_id` int(11) DEFAULT NULL,
  `ca1` int(11) DEFAULT NULL,
  `ca2` int(11) DEFAULT NULL,
  `ca3` int(11) DEFAULT NULL,
  `ca4` int(11) DEFAULT NULL,
  `ca5` float(10,1) DEFAULT NULL,
  `ca6` float(10,1) DEFAULT NULL,
  `project` int(11) DEFAULT NULL,
  `affective` int(11) DEFAULT NULL,
  `psychomotor` int(11) DEFAULT NULL,
  `exam` int(11) DEFAULT NULL,
  `tot_score` int(11) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `modified_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


总计列将从控制器自动计算。i、 e所有考试成绩+考试成绩。 然后根据总分得到最高分和最低分

一切正常,但由于目前的情况(新冠病毒-19大流行),需要做出改变,这就是问题现在出现的地方

现在,在学校关闭之前,只输入考试分数(即从ca1到ca6)。他们不能写他们的考试,因此考试栏有一个空白点

为了纠正这一点,得出了一个结论,即计算所有CA的总数,将其乘以40,再除以60

CAs总数X 40/60

那会给你考试分数

我对编码不是很在行。可以说我比新手差。然而,我试图在视图中计算考试和总分。 我现在被困在如何得到最高和最低的分数,因为他们是从一个查询中得到的

最高/最低分数的模型


  public function GetHighestScore($subject_id, $session_id, $section_id, $class_id) 
    {
        $this->db->select_max('tot_score');
        $this->db->where('subject_id', $subject_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        return $this->db->get('scores_primary')->row(); 
    }

    public function GetLowestScore($subject_id, $session_id, $section_id, $class_id) 
    {
        $this->db->select_min('tot_score');
        $this->db->where('subject_id', $subject_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        return $this->db->get('scores_primary')->row(); 
    }

public function GetHighestScore($subject_id, $session_id, $section_id, $class_id)
    {
        $data = $this->primary_model->GetHighestScore($subject_id, $session_id, $section_id, $class_id); 
        return $data->tot_score;
    }


    public function GetLowestScore($subject_id, $session_id, $section_id, $class_id)
    {
        $data = $this->primary_model->GetLowestScore($subject_id, $session_id, $section_id, $class_id); 
        return $data->tot_score;
    }

最高和最低分数的控制器


  public function GetHighestScore($subject_id, $session_id, $section_id, $class_id) 
    {
        $this->db->select_max('tot_score');
        $this->db->where('subject_id', $subject_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        return $this->db->get('scores_primary')->row(); 
    }

    public function GetLowestScore($subject_id, $session_id, $section_id, $class_id) 
    {
        $this->db->select_min('tot_score');
        $this->db->where('subject_id', $subject_id);
        $this->db->where('session_id', $session_id);
        $this->db->where('section_id', $section_id);
        $this->db->where('class_id', $class_id);
        return $this->db->get('scores_primary')->row(); 
    }

public function GetHighestScore($subject_id, $session_id, $section_id, $class_id)
    {
        $data = $this->primary_model->GetHighestScore($subject_id, $session_id, $section_id, $class_id); 
        return $data->tot_score;
    }


    public function GetLowestScore($subject_id, $session_id, $section_id, $class_id)
    {
        $data = $this->primary_model->GetLowestScore($subject_id, $session_id, $section_id, $class_id); 
        return $data->tot_score;
    }

视图

 <td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetHighestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id, $value->class_id); ?></td>

<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetLowestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id); ?></td>

 <tr>
<td style="border: 1px solid black; font-size:11px;width:120px;white-space: nowrap;height:30px;">
<?php echo $CI->GetSubjectNameWithID($value->subject_id); ?>
</td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca1; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca3; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca4; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->project; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->affective; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->psychomotor; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca1 + $value->ca3 + $value->ca4 + $value->project + $value->affective + $value->psychomotor; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo round($value->ca1 *40/60 + $value->ca3*40/60 + $value->ca4*40/60 + $value->project*40/60 + $value->affective*40/60 + $value->psychomotor*40/60, 1); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo round($value->tot_score = $value->ca1 *40/60 + $value->ca3*40/60 + $value->ca4*40/60 + $value->project*40/60 + $value->affective*40/60 + $value->psychomotor*40/60 + $value->ca1 + $value->ca3 + $value->ca4 + $value->project + $value->affective + $value->psychomotor, 1); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $grade; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetHighestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id, $value->class_id); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetLowestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;white-space: nowrap;">
                                                <?php

$scores2 = $CI->GetSubjectScores($value->subject_id, $value->session_id, $value->section_id, $value->class_id); //echo $value->pos;

$scores = array_column($scores2, 'tot_score');

$pos = array_search($value->tot_score, $scores);
 //var_dump($pos);
 $number = $pos + 1;

echo $CI->ordinal($number);
?>
</td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $remark; ?></td>
</tr>


因为我从视图中计算了考试和总分,所以上面的代码为空,因为总分现在在视图中是直接计算的

我现在有没有办法通过我的计算得到全班最高和最低的分数?或者,我如何在控制器中进行此计算,以便自动生成类中的总数、最高值和最低值,就像它们使用的那样

controller

function assigngradeAction() 
{
      for($i=0; $i<count($this->input->post('number')); $i++)
                {

                    $data[]=array(
                        'section_id' => $this->input->post('section_id'),
                        'subject_id' => $this->input->post('subject_id'),
                        'class_id' => $this->input->post('class_id')[$i],
                        'student_id' => $this->input->post('student_id')[$i],
                        'session_id' => $this->input->post('session_id'),
                        'ca1' => $this->input->post('ca1')[$i],
                        'ca2' => $this->input->post('ca2')[$i],
                        'ca3' => $this->input->post('ca3')[$i],
                        'ca4' => $this->input->post('ca4')[$i],
                        'project' => $this->input->post('project')[$i],
                        'affective' => $this->input->post('affective')[$i],
                        'psychomotor' => $this->input->post('psychomotor')[$i],
                        'exam' => $this->input->post('exam')[$i],
            'tot_score'=> $this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i] + $this->input->post('exam')[$i],

        }






        //var_dump($data);

        $inserted = $this->primary_model->add2($data2);
        if($inserted)
        {
            $this->session->set_flashdata('msg', '<div class="alert alert-success">Grade Added successfully</div>');
            //Echo back success json
            redirect('admin/teacher/GetStudentForSubject');
        }

    }

函数赋值操作()
{
对于($i=0;$iinput->post('number');$i++)
{
$data[]=数组(
'section\u id'=>this->input->post('section\u id'),
'subject\u id'=>this->input->post('subject\u id'),
'class_id'=>this->input->post('class_id')[$i],
'student_id'=>this->input->post('student_id')[$i],
'session\u id'=>this->input->post('session\u id'),
“ca1”=>$this->input->post('ca1')[$i],
“ca2”=>$this->input->post('ca2')[$i],
“ca3”=>$this->input->post('ca3')[$i],
“ca4”=>$this->input->post('ca4')[$i],
“项目”=>$this->input->post('project')[$i],
'affective'=>$this->input->post('affective')[$i],
“精神运动”=>$this->input->post('psychomotor')[$i],
“考试”=>$this->input->post('exam')[$i],
‘tot_score’=>$this->input->post('ca1')[$i]+$this->input->post('ca2')[$i]+$this->input->post('ca4')[$i]+$this->input->post('project')[$i]+$this->input->post('fective')[$i]+$this->input->post('psychormotomotor')[$i]+$this->input->post('考试')[$i],
}
//var_dump($数据);
$inserted=$this->primary\u model->add2($data2);
如果有($插入)
{
$this->session->set_flashdata('msg','Grade Added successfully');
//回显成功json
重定向('admin/teacher/GetStudentForSubject');
}
}
查看

 <td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetHighestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id, $value->class_id); ?></td>

<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetLowestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id); ?></td>

 <tr>
<td style="border: 1px solid black; font-size:11px;width:120px;white-space: nowrap;height:30px;">
<?php echo $CI->GetSubjectNameWithID($value->subject_id); ?>
</td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca1; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca3; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca4; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->project; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->affective; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->psychomotor; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $value->ca1 + $value->ca3 + $value->ca4 + $value->project + $value->affective + $value->psychomotor; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo round($value->ca1 *40/60 + $value->ca3*40/60 + $value->ca4*40/60 + $value->project*40/60 + $value->affective*40/60 + $value->psychomotor*40/60, 1); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo round($value->tot_score = $value->ca1 *40/60 + $value->ca3*40/60 + $value->ca4*40/60 + $value->project*40/60 + $value->affective*40/60 + $value->psychomotor*40/60 + $value->ca1 + $value->ca3 + $value->ca4 + $value->project + $value->affective + $value->psychomotor, 1); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $grade; ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetHighestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id, $value->class_id); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $CI->GetLowestScore($value->subject_id, $value->session_id, $value->section_id, $value->class_id); ?></td>
<td style="border: 1px solid black; font-size:11px;width:120px;white-space: nowrap;">
                                                <?php

$scores2 = $CI->GetSubjectScores($value->subject_id, $value->session_id, $value->section_id, $value->class_id); //echo $value->pos;

$scores = array_column($scores2, 'tot_score');

$pos = array_search($value->tot_score, $scores);
 //var_dump($pos);
 $number = $pos + 1;

echo $CI->ordinal($number);
?>
</td>
<td style="border: 1px solid black; font-size:11px;width:120px;text-align:center;"><?php echo $remark; ?></td>
</tr>


在控制器中存储检查编号。您需要检查一个条件,即如果检查编号为空,则计算总ca,然后乘除(应用逻辑)。

请记住,这只是一个临时解决方案,一旦所有数据都被删除 如果已保存,则应撤消更改或注释掉它(如果需要) 以后再使用。



控制器->函数AssignGrade SingleStudentAction()->elseif条件
//(我假设此问题仅适用于代码建议的elseif条件)

else if($this->input->post('class') >= 4 && $this->input->post('class') <= 17)
{

    $data2['section_id']  = $this->input->post('section_id');
    $data2['subject_id']  = $this->input->post('subject_id');
    $data2['class_id']    = $this->input->post('class_id');
    $data2['student_id']  = $this->input->post('student_id');
    $data2['session_id']  = $this->input->post('session_id');
    $data2['ca1']         = $this->input->post('ca1');
    $data2['ca2']         = $this->input->post('ca2');
    $data2['ca3']         = $this->input->post('ca3');
    $data2['ca4']         = $this->input->post('ca4');
    $data2['project']     = $this->input->post('project');
    $data2['affective']   = $this->input->post('affective');
    $data2['psychomotor'] = $this->input->post('psychomotor');

    /* No change till here */
    if( !empty( $this->input->post('exam') )){

        $data2['exam']    = $this->input->post('exam');

    }else{

        $data2['exam']    = ( ( $data2['ca1'] + $data2['ca2'] + $data2['ca3'] + $data2['ca4']) * 40 )/ 60;
    }  // comment this else condition after your work is done.

    $data2['tot_score']   = $this->input->post('ca1') + $this->input->post('ca2') + $this->input->post('ca3') + $this->input->post('ca4') + $this->input->post('project') + $this->input->post('affective') + $this->input->post('psychomotor') + $data2['exam'];
}
else如果($this->input->post('class')>=4&&$this->input->post('class')input->post('section_id');
$data2['subject\u id']=$this->input->post('subject\u id');
$data2['class_id']=$this->input->post('class_id');
$data2['student_id']=$this->input->post('student_id');
$data2['session\u id']=$this->input->post('session\u id');
$data2['ca1']=$this->input->post('ca1');
$data2['ca2']=$this->input->post('ca2');
$data2['ca3']=$this->input->post('ca3');
$data2['ca4']=$this->input->post('ca4');
$data2['project']=$this->input->post('project');
$data2['affective']=$this->input->post('affective');
$data2['psychomotor']=$this->input->post('psychomotor');
/*在这里之前没有变化*/
如果(!empty($this->input->post('exam')){
$data2['exam']=$this->input->post('exam');
}否则{
$data2['ca1']=($data2['ca1']+$data2['ca2']+$data2['ca3']+$data2['ca4'])40)/60;
}//在您的工作完成后,注释此else条件。
$data2['tot_score']=$this->input->post('ca1')+$this->input->post('ca2')+$this->input->post('ca3')+$this->input->post('ca4')+$this->input->post('project')+$this->input->post('fectivement')+$this->input->post('psychormotmotor')+$this->input(';
}

这应该对您有所帮助。

这就是我使用@sauhardnc解决方案所做的

function assigngradeAction() 
{

            for($i=0; $i<count($this->input->post('number')); $i++)
                {

                     $data[]=array(
                        'section_id' => $this->input->post('section_id'),
                        'subject_id' => $this->input->post('subject_id'),
                        'class_id' => $this->input->post('class_id')[$i],
                        'student_id' => $this->input->post('student_id')[$i],
                        'session_id' => $this->input->post('session_id'),
                        'ca1' => $this->input->post('ca1')[$i],
                        'ca2' => $this->input->post('ca2')[$i],
                        'ca3' => $this->input->post('ca3')[$i],
                        'ca4' => $this->input->post('ca4')[$i],
                        'project' => $this->input->post('project')[$i],
                        'affective' => $this->input->post('affective')[$i],
                        'psychomotor' => $this->input->post('psychomotor')[$i],
                        'exam'=> !empty( $this->input->post('exam')[$i] ) ? $this->input->post('exam')[$i] : ($this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i]) * 40 / 60,
                        'tot_score'=> $this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i] + $this->input->post('exam')[$i] + ($this->input->post('ca1')[$i] + $this->input->post('ca2')[$i] + $this->input->post('ca3')[$i] + $this->input->post('ca4')[$i] + $this->input->post('project')[$i] + $this->input->post('affective')[$i] + $this->input->post('psychomotor')[$i]) * 40 / 60,
}   

                    );

                }




                 $inserted = $this->primary_model->add1($data);
                 if($inserted > 0)
                 {
                     $this->session->set_flashdata('msg', '<div class="alert alert-success">Grade Added successfully</div>');
                     //Echo back success json
                     redirect('admin/primary/index');
                  }           

    }

函数赋值操作()
{
对于($i=0;$iinput->post('number');$i++)
{
$data[]=数组(
'section\u id'=>this->input->post('section\u id'),
'subject\u id'=>this->input->post('subject\u id'),
'class_id'=>this->input->post('class_id')[$i],
'student_id'=>this->input->post('student_id')[$i],