я столкнулся с проблемой с какой-то логической ошибкой - PullRequest
1 голос
/ 28 сентября 2019

Я хочу суммировать индивидуальный номер студента с некоторым условием.Условие состоит в том, что если ученик провалит какой-либо один предмет, он даст мне значение 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');
}

o

вывод (я получаю):

3213
3171
1248
2989
4291
0
0
0
0
0
0
0
0

вывод (я хочу):

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

значение student_array (это все идентификаторы студента):

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
)

значение exam_array:

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
        )
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...