Почему идентификаторы сеансов в моей таблице меняются на 0? - PullRequest
0 голосов
/ 30 апреля 2020

У меня есть форма для представления результатов учеников, которая должна захватывать идентификатор сессии (идентификаторы сессии используются, чтобы показать сессию, в которой в данный момент находится школа, например, сессия 2018/2019, сессия 2019/2020 ...)

таблица сеансов

В таблице результатов в базе данных идентификатор сеанса автоматически фиксируется и вставляется. В настоящее время идентификатор сеанса равен 14.

идентификатор сеанса

Однако по неизвестным причинам вместо 14 вставляются 0, что вызывает столько проблем

  1. В форме добавления баллов значения баллов заполняются только в том случае, если идентификатор сеанса равен 14. Теперь, поскольку он показывает 0, поля значений остаются 0

  2. Также я считаю, что это вызывает дублирующие проблемы. Во время редактирования формы все баллы учащихся дублируются.

Контроллер

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],
                    );

                }




                 $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');
                  }           

    }

модель

public function add1($data)
    {

        // for each record insert
        foreach($data as $studentScore){
            // get score
            $subjectId = $studentScore['subject_id'];
            $classId = $studentScore['class_id'];
            $sessionId = $studentScore['session_id'];
            $sectionId = $studentScore['section_id'];
            $studentId = $studentScore['student_id'];
            $score = $this->get_student_score($subjectId,$sessionId,$sectionId,$classId,$studentId); 
            $studentScore['modified_at'] = date("Y-m-d H:i:s");
            if(empty($score->id)){
                $this->db->insert('scores_primary', $studentScore);
            }else{
                $this->db->where('id', $score->id);
                $this->db->update('scores_primary', $studentScore);
            }
           // var_dump($studentScore, "\n >>>>>>>>", $score);

        }
    //   $this->db->insert_batch('scores_primary', $data);
    //   var_dump($this->db->error(), $_SERVER['SERVER_ADDR'] );
    //   $str = $this->db->last_query();

    // echo "<pre>";
    // print_r($str);
       return true; 
    }

просмотр

<?php }elseif($class_id >= 15 && $class_id <= 17){ ?>
                            <form action="<?php echo site_url('admin/primary/assigngradeAction') ?>" method="POST" id="formSubjectTeacher">
                               <?php echo $this->customlib->getCSRF(); ?>
                               <div class="row">
                                        <div class="col-lg-3">
                                        <input type="hidden" name="class" value="<?php echo $class_id; ?>">
                                            <input type="hidden" name="subject_id" value="<?php echo $subject_id; ?>">
                                        </div>
                                        <div class="col-lg-4">

                                        <h4><strong><?php echo $session_name; ?></strong></h4>
                                        </div>
                                    </div>
                                    <br>
                                    <hr>

                                <?php foreach($students as $student){ ?>
                                    <div class="row">
                                        <div class="col-lg-3">
                                        <div class="form-group">
                                                <label>Student Name</label>
                                                <input type="hidden" name="number[]"  value="">
                                                <input type="hidden" name="section_id"  value="<?php echo $section_id; ?>">
                                                <input type="hidden" name="session_id"  value="<?php echo $student->session_id; ?>">
                                                <input type="hidden" name="student_id[]"  value="<?php echo $student->student_id; ?>">
                                                <input type="hidden" name="class_id[]" value="<?php echo $class_id; ?>">
                                                <input type="text" value="<?php echo $CI->GetStudentNameWithID($student->student_id); ?>" class="form-control "  readonly>
                                            </div>
                                        </div>
                                        <div class="col-lg-1">
                                            <label>ca1 </label>
                                            <input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">
                                            <input type="number" name="ca1[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca1: 0; ?>">
                                        </div>
                                        <div class="col-lg-1" id="t2">
                                            <label>ca2</label>
                                            <input type="number" name="ca2[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca2: 0; ?>">
                                        </div>
                                        <div class="col-lg-1" id="assg">
                                            <label>ca3</label>
                                            <input type="number" name="ca3[]" min="0" max="10" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->ca3: 0; ?>">
                                        </div>
                                        <div class="col-lg-1" id="exam">
                                            <label>Exam</label>
                                            <input type="number" name="exam[]" min="0" max="70" class="form-control input-sm rounded-0" value="<?php echo $student->scores? $student->scores->exam: 0; ?>">
                                        </div>
                                        <div class="col-lg-1">
                                            <label>Total</label>
                                            <output class="result"></output>
                                        </div>
                                    </div>

                              <?php } ?>

1 Ответ

0 голосов
/ 01 мая 2020

в вашем view в form у вас есть два input fields с именем session_id ↓↓

  1. <input type="hidden" name="session_id" value="<?php echo $student->session_id; ?>">

  2. <input type="hidden" name="session_id" value="<?php echo $sessionID; ?>">

Повторяющиеся поля могут вызвать проблемы, проверьте, какое из них имеет правильное значение, и отбросьте другое. Если оба поля имеют неправильные значения, проверьте, где эти значения инициализируются, и так далее. Вот как вы отлаживаете в PHP.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...