Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.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_Codeigniter 3 - Fatal编程技术网

Php 我面临着一些逻辑错误的问题

Php 我面临着一些逻辑错误的问题,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我想在一定条件下对每个学生的人数求和。条件是,如果一个学生没有通过任何一门课程,那么它将给我0值,而不是他的任何数字的总和。当使用这个条件时,它会给我错误的值。现在这些都是我面临的问题,我尝试了很多东西,但都没有成功。在下文中,我将向您提供代码、输出以及我想要的输出 控制器: if (!empty($examSchedule)) { $new_array = array(); foreach ($studentList as $stu_key => $stu_value)

我想在一定条件下对每个学生的人数求和。条件是,如果一个学生没有通过任何一门课程,那么它将给我0值,而不是他的任何数字的总和。当使用这个条件时,它会给我错误的值。现在这些都是我面临的问题,我尝试了很多东西,但都没有成功。在下文中,我将向您提供代码、输出以及我想要的输出

控制器:

if (!empty($examSchedule)) {
    $new_array = array();
    foreach ($studentList as $stu_key => $stu_value) {
        $array = array();
        $array['student_id'] = $stu_value['id'];
        $array['admission_no'] = $stu_value['admission_no'];
        $array['roll_no'] = $stu_value['roll_no'];
        $array['firstname'] = $stu_value['firstname'];
        $array['lastname'] = $stu_value['lastname'];
        $array['dob'] = $stu_value['dob'];
        $array['father_name'] = $stu_value['father_name'];
        $x = array();
        foreach ($examSchedule as $ex_key => $ex_value) {
            $exam_array = array();
            $exam_array['exam_schedule_id'] = $ex_value['id'];
            $exam_array['exam_id'] = $ex_value['exam_id'];
            $exam_array['subject_id'] = $ex_value['subject_id'];
            $exam_array['full_marks'] = $ex_value['full_marks'];
            $exam_array['passing_marks'] = $ex_value['passing_marks'];
            $exam_array['exam_name'] = $ex_value['name'];
            $exam_array['exam_type'] = $ex_value['type'];
            $student_exam_result = $this->examresult_model->get_exam_result($ex_value['id'], $stu_value['id']);
            $exam_array['attendence'] = $student_exam_result->attendence;
            $exam_array['get_marks'] = $student_exam_result->get_marks;
            $x[] = $exam_array;
        }
        $array['exam_array'] = $x;
        $new_array[] = $array;
    }
    $data['examSchedule'] = $new_array;
}

if ($this->input->post('save_exam') == "save_exam") {
    $ex_array = array();
    $exam_id = $this->input->post('exam_id');
    $student_array = $this->input->post('student');
    $exam_array = $this->input->post('exam_schedule');
    $total_marks = array();
    foreach ($student_array as $key => $student) {
        foreach ($examSchedule as $ex_key => $ex_value) {
        foreach ($exam_array as $key => $exam) {
            $record['get_marks'] = 0;
            $record['attendence'] = "pre";
            if ($this->input->post('student_absent' . $student . "_" . $exam) == "") {
                $get_marks = $this->input->post('student_number' . $student . "_" . $exam);
                $record['get_marks'] = $get_marks;

                $passing_marks = $ex_value['passing_marks'];
                if ($get_marks != '0' && $get_marks>=$passing_marks) {
                    $total_marks[$student] += $get_marks; 

                } else {
                     $total_marks[$student] = 0;
                     break;    
                }


            } else {
                $record['attendence'] = $this->input->post('student_absent' . $student . "_" . $exam);
                                        }
            $record['exam_schedule_id'] = $exam;
            $record['student_id'] = $student;
            $record['exam_id'] = $exam_id;


            $inserted_id = $this->examresult_model->add_exam_result($record);

            if ($inserted_id) {
                $ex_array[$student] = $exam_id;
            }

        }


        $total['total_mark'] = $total_marks[$student];                           
        $total['exam_id'] = $this->input->post('exam_id');
        $total['student_id'] = $student;
        $total['class_id'] = $class_id;
        $total['section_id'] = $section_id;
        $total['year'] = date("Y");

        $total_mark = $this->examresult_model->add_total_result($total);

    }
    echo "<pre>";
        print_r( $total['total_mark']);
}    
exit();

    if (!empty($ex_array)) {
        $this->mailsmsconf->mailsms('exam_result', $ex_array, NULL, $exam_array);
    }
    redirect('admin/mark');
}
输出(我想要):

student_数组的值(这些都是student id):

检查\u数组的值:

Array
(
    [0] => Array
        (
            [student_id] => 110
            [admission_no] => 01
            [roll_no] => 01
            [firstname] => Md. Abdur
            [lastname] => Rahaman
            [dob] => 2015-05-12
            [father_name] => Sowpan Chow
            [exam_array] => Array
                (
                    [0] => Array
                        (
                            [exam_schedule_id] => 84
                            [exam_id] => 7
                            [subject_id] => 4
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Bangla
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 75.00
                        )

                    [1] => Array
                        (
                            [exam_schedule_id] => 85
                            [exam_id] => 7
                            [subject_id] => 1
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => English
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 82.00
                        )

                    [2] => Array
                        (
                            [exam_schedule_id] => 86
                            [exam_id] => 7
                            [subject_id] => 2
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Math
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 88.00
                        )

                    [3] => Array
                        (
                            [exam_schedule_id] => 87
                            [exam_id] => 7
                            [subject_id] => 3
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Religion
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 87.00
                        )

                    [4] => Array
                        (
                            [exam_schedule_id] => 88
                            [exam_id] => 7
                            [subject_id] => 10
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => Art & Craft
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 45.00
                        )

                    [5] => Array
                        (
                            [exam_schedule_id] => 89
                            [exam_id] => 7
                            [subject_id] => 9
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => General Knowledge
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 42.00
                        )

                    [6] => Array
                        (
                            [exam_schedule_id] => 90
                            [exam_id] => 7
                            [subject_id] => 11
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => Computer
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 40.00
                        )

                )

        )
 [1] => Array
        (
           #value
        )
[2] => Array
        (
           #value
        )
[3] => Array
        (
           #value
        )
[4] => Array
        (
           #value
        )
[5] => Array
        (
           #value
        )..
[12] => Array
        (
           #value
        )
examSchedule的值:


您可以进行单独的
foreach
循环,以获得单个学生的全部分数,然后在进行及格分数验证/添加之前,检查其是否包含任何
0
分数:

if($this->input->post('save_-test')==“save_-test”){
$ex_数组=数组();
$exam\u id=$this->input->post('exam\u id');
$student_array=$this->input->post('student');
$exam_数组=$this->input->post('exam_时间表');
$total_marks=array();
foreach($student\u数组作为$key=>$student){
//检查当前学生是否有0分
$student_mark=[];
foreach($exam\u数组作为$key=>$exam){
$student\u mark[$student][=$this->input->post('student\u number'.$student.'.'.$test));
}
$zero\u mark\u flag=在\u数组中(0,$student\u mark[$student],true)?true:false;//如果包含0个标记,则返回true
foreach($examSchedule as$ex_key=>$ex_value){
foreach($exam\u数组作为$key=>$exam){
$record['get_marks']=0;
$record['attentince']=“pre”;
如果($this->input->post($student.$student.$test)==“”){
$get_marks=$this->input->post('student_number'.$student.'.'.$test);
$record['get_marks']=$get_marks;
$passing_marks=$ex_值['passing_marks'];
//一个或多个学生分数为0,因此跳过添加分数
如果($zero\u mark\u flag===true){
$total_分数[$student]=0;
打破
}否则,如果($get\u marks!=“0”&&$get\u marks>=$传递\u标记){
$total_分数[$student]+=$get_分数;
}
}否则{
$record['attendence']=$this->input->post('student\u缺席'。$student.'.\u.$test);
}
$record['exam\u schedule\u id']=$exam;
$record['student_id']=$student;
$record['exam\u id']=$exam\u id;
$inserted\u id=$this->examresult\u model->add\u exam\u result($record);
如果($inserted\u id){
$ex_数组[$student]=$ex_id;
}
}
$total['total_mark']=$total_marks[$student];
$total['exam_id']=$this->input->post('exam_id');
$total['student_id']=$student;
$total['class\u id']=$class\u id;
$total['section\u id']=$section\u id;
$total['year']=日期(“Y”);
$total\u mark=$this->examresult\u model->add\u total\u result($total);
}
回声“;
打印($total['total_mark']);
}    
退出();
如果(!空($ex_数组)){
$this->mailsmsconf->mailsms('exam\u result',$ex\u array,NULL,$exam\u array);
}
重定向(“管理/标记”);
}

因此,学生分数将始终设置为0。

您可以对每个学生进行单独的
foreach
循环,以获得单个学生的全部分数,然后在进行及格分数验证/添加之前检查其上是否包含任何
0
分数:

if($this->input->post('save_-test')==“save_-test”){
$ex_数组=数组();
$exam\u id=$this->input->post('exam\u id');
$student_array=$this->input->post('student');
$exam_数组=$this->input->post('exam_时间表');
$total_marks=array();
foreach($student\u数组作为$key=>$student){
//检查当前学生是否有0分
$student_mark=[];
foreach($exam\u数组作为$key=>$exam){
$student\u mark[$student][=$this->input->post('student\u number'.$student.'.'.$test));
}
$zero\u mark\u flag=在\u数组中(0,$student\u mark[$student],true)?true:false;//如果包含0个标记,则返回true
foreach($examSchedule as$ex_key=>$ex_value){
foreach($exam\u数组作为$key=>$exam){
$record['get_marks']=0;
$record['attentince']=“pre”;
如果($this->input->post($student.$student.$test)==“”){
$get_marks=$this->input->post('student_number'.$student.'.'.$test);
$record['get_marks']=$get_marks;
$passing_marks=$ex_值['passing_marks'];
//一个或多个学生分数为0,因此跳过添加分数
如果($zero\u mark\u flag===true){
$total_分数[$student]=0;
打破
}else if($get_marks!='0'&&$get_marks>=$passing_marks){
$total_分数[$student]+=$get_分数;
}
}否则{
$record['attendence']=$this->input->post('student\u缺席'。$student.'.\u.$test);
}
$record['exam\u schedule\u id']=$exam;
$record['student_id']=$student;
$record['exam\u id']=$exam\u id;
$inserted\u id=$this->examresult\u model->add\u exam\u result($record);
如果($inserted\u id){
$ex_数组[$student]=$ex_id;
}
}
$total['total_mark']=$total_marks[$student];
459
453
416
0 //(427 is the sum but one subject fail thatswhy it sum zero)
613
0
0
0
0
0
0
0
0
Array(
    [0] => 110
    [1] => 111
    [2] => 120
    [3] => 121
    [4] => 112
    [5] => 113
    [6] => 114
    [7] => 122
    [8] => 115
    [9] => 116
    [10] => 117
    [11] => 118
    [12] => 119
)
Array
(
    [0] => 84
    [1] => 85
    [2] => 86
    [3] => 87
    [4] => 88
    [5] => 89
    [6] => 90
)
Array
(
    [0] => Array
        (
            [student_id] => 110
            [admission_no] => 01
            [roll_no] => 01
            [firstname] => Md. Abdur
            [lastname] => Rahaman
            [dob] => 2015-05-12
            [father_name] => Sowpan Chow
            [exam_array] => Array
                (
                    [0] => Array
                        (
                            [exam_schedule_id] => 84
                            [exam_id] => 7
                            [subject_id] => 4
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Bangla
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 75.00
                        )

                    [1] => Array
                        (
                            [exam_schedule_id] => 85
                            [exam_id] => 7
                            [subject_id] => 1
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => English
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 82.00
                        )

                    [2] => Array
                        (
                            [exam_schedule_id] => 86
                            [exam_id] => 7
                            [subject_id] => 2
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Math
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 88.00
                        )

                    [3] => Array
                        (
                            [exam_schedule_id] => 87
                            [exam_id] => 7
                            [subject_id] => 3
                            [full_marks] => 100
                            [passing_marks] => 33
                            [exam_name] => Religion
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 87.00
                        )

                    [4] => Array
                        (
                            [exam_schedule_id] => 88
                            [exam_id] => 7
                            [subject_id] => 10
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => Art & Craft
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 45.00
                        )

                    [5] => Array
                        (
                            [exam_schedule_id] => 89
                            [exam_id] => 7
                            [subject_id] => 9
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => General Knowledge
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 42.00
                        )

                    [6] => Array
                        (
                            [exam_schedule_id] => 90
                            [exam_id] => 7
                            [subject_id] => 11
                            [full_marks] => 50
                            [passing_marks] => 16
                            [exam_name] => Computer
                            [exam_type] => Theory
                            [attendence] => pre
                            [get_marks] => 40.00
                        )

                )

        )
 [1] => Array
        (
           #value
        )
[2] => Array
        (
           #value
        )
[3] => Array
        (
           #value
        )
[4] => Array
        (
           #value
        )
[5] => Array
        (
           #value
        )..
[12] => Array
        (
           #value
        )