如何将一批学生从一学期推广到另一学期?

时间:2017-07-01 11:00:48

标签: php html css mysql codeigniter

我想从第1学期到第2学期推广一批学生。

---------------控制器--------------------



npm install -g @angular/cli@latest



 我有表学生,课程,学期,批次

-------------------模型---------------------



public function display_promote_student()
    {   
      if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && $_SESSION['role'] === '1' && $_SESSION['role_des'] === 'admin')
      {
         $data['batch']=$this->Student_model->get_all_batch();
         $data['course']=$this->Student_model->get_all_course();
         $data['sem']=$this->Student_model->get_all_sem();
         if($data)
          {
             $this->load->view('Admin/header');     
             $this->load->view('Admin/promote_students', $data);
          }
          else
          {
            redirect('Admin/index','refresh'); 
          }
      }
      else
      {
      redirect('Admin/index');
      }
    }
  public function list_promote_student_view()
    { 
      if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && $_SESSION['role'] === '1' && $_SESSION['role_des'] === 'admin')
      {
          $course=$this->input->post('course');
          $sem=$this->input->post('sem');
          $batch=$this->input->post('batch');
          $data['course']=$course;
          $data['sem']=$sem;
          $data['batch']=$batch;
          $data['promote'] = $this->Student_model->get_all_student_by_cour_sem($course,$sem,$batch);
          $this->load->view('Admin/header');     
          $this->load->view('Admin/list_promote_students',$data);
      }
    }
  public function promote_semester_processing()
    { 
      if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && $_SESSION['role'] === '1' && $_SESSION['role_des'] === 'admin')
      {
        $course=$this->input->post('course');
        $sem=$this->input->post('sem');
        $batch=$this->input->post('batch');
        $new_sem=$this->input->post('newsem');
        $results = $this->Student_model->get_all_student_by_cour_sem($course,$sem,$batch);
        $dep_id = [$results];
        //var_dump( $dep_id);die();
        $prodate = date('Y-m-d');
        $month = strtotime($prodate);
        $promonth = date('m',$month);
        foreach($results  as  $val)
        {
          $dep_id = $val['student_id'];
          $db_date = $val['promote_date'];
          $db_month =  strtotime($db_date);
          $pro_month = date('m',$db_month);
          $cal = $pro_month +5;
          $data = array(
                  'sem_id' =>$new_sem,
                  'promote_date' =>$prodate);
          if($db_date == 0)
          {
              $id=$this->Student_model->update_semester($dep_id,$data);
              if($id)
              {
                $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Promote Semester Successfully... </div>');    
                redirect('Admin/display_promote_student');
              } 
              else
              {
                $this->session->set_flashdata('msg','<div class="alert alert-success text-center">Promote Semester not Successfully... </div>');    
                redirect('Admin/display_promote_student');
              }
            }
          elseif ($promonth == $cal) 
          {
              $id=$this->Student_model->update_semester($dep_id,$data);
          }
          else
          {
             $this->session->set_flashdata('msg','<div class="alert alert-success text-center">You can promote only after six months... </div>');    
             redirect('Admin/display_promote_student');
          }
        }
      }
    }
&#13;
&#13;
&#13;

-------------------------视图--------------------- ---

promote_student

&#13;
&#13;
public function get_all_student_by_cour_sem($course,$sem,$batch)
  {
    $this->db->select( 'tbl_student.*, tbl_course.*,tbl_semester.*,tbl_batch.*');    
    $this->db->from('tbl_student'); 
    $this->db->join('tbl_course','tbl_course.course_id = tbl_student.course_id','left');
    $this->db->join('tbl_semester', 'tbl_semester.sem_id = tbl_student.sem_id','left');
    $this->db->join('tbl_batch', 'tbl_batch.batch_id = tbl_student.stud_batch_id','left');
    $this->db->where('tbl_student.course_id',$course);
    $this->db->where('tbl_student.sem_id',$sem);
    $this->db->where('tbl_student.stud_batch_id',$batch);
    $query = $this->db->get();
    return $query->result_array(); 
  }
  public function update_semester($dep_id,$data)
  {
    $this->db->where('student_id',$dep_id);
    return  $query = $this->db->update('tbl_student',$data);
  }
&#13;
&#13;
&#13;

List_promote_students

&#13;
&#13;
<div class="container">
     <div class="col-md-10 col-md-offset-1">
     <h4><?php echo $this->session->flashdata('msg'); ?></h4><br>
<div class="panel panel-default">
            <div class="panel-heading">
              <h3>Promote Students</h3>
            </div>
            <?php $attributes = array("name" => "promote", "class" => "form-horizontal");
                echo form_open_multipart("Admin/list_promote_student_view", $attributes);?>
              <div class="panel-body">
                   <div class="form-group has-feedback">
                  <label for="title" class="col-sm-2 control-label">Course</label>
                  <div class="col-sm-6">
				  <select class="form-control" name="course" required>
				  <option>--Choose a Course--</option>
                  <?php 
     foreach($course as $row)
     { 
       echo '<option value="'.$row->course_id.'">'.$row->c_name.'</option>';
     }?>
				  </select>
                <span class="text-danger"><?php echo form_error('course'); ?></span>
                  </div>
				    </div>
			  
           	   <div class="form-group has-feedback">
                  <label for="semester" class="col-sm-2 control-label" placeholder="">Semester</label>
                  <div class="col-sm-6">
				   
                    <select class="form-control" name="sem" required>
<option>--Choose a Semester--</option>
                  <?php 
     foreach($sem as $row)
     { 
       echo '<option value="'.$row->sem_id.'">'.$row->sem_code.'</option>';
     }?>
			    </select>
                <span class="text-danger"><?php echo form_error('semester'); ?></span>
                  </div>
				  </div>
				     <div class="form-group has-feedback">
                  <label for="title" class="col-sm-2 control-label">Year</label>
                  <div class="col-sm-6">
                    <select class="form-control" name="batch" required>
                     <option>--Choose Batch--</option>
                  <?php 
     foreach($batch as $row)
     { 
       echo '<option value="'.$row->batch_id.'">'.$row->batch_year.'</option>';
     }?>
                  </select>
                    </div>
                <span class="text-danger"><?php echo form_error('year'); ?></span>
                  </div>
                </div>
              <div class="box-footer col-md-offset-4">
              <button type="submit" class="btn btn-warning">Submit</button>
              </div>
            <?php echo form_close(); ?>
          </div>
          </div>
          </div>
&#13;
&#13;
&#13;

只有一名学生获得此代码的晋升机会。但我想在下学期推广一批学生。我该怎么做?

请尽早帮助我。

1 个答案:

答案 0 :(得分:0)

目前您正在使用循环逐个更新学生,但您应该在模型的 update_semester($ dep_id)中使用codeigniter的 update_batch 功能,$ data)功能。您还必须在$ data参数中传递所有学生数据。

Codeigniter update_batch function link

您的代码中的问题: - 问题出在您的控制器的 promote_semester_processing()功能中。在 foreach循环中,只要第一个用户的学期成功更新,您就可以使用重定向(&#39; Admin / display_promote_student&#39;); 设置Flash数据 $ this-&gt; session-&gt; set_flashdata(&#39; msg&#39;,&#39;促进学期成功......&#39;); ,刷新页面,因此下一个更新查询将永远不会执行。



在您发表评论后更新了promote_semester_processing()函数

public function promote_semester_processing()
{
    if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true && $_SESSION['role'] === '1' && $_SESSION['role_des'] === 'admin')
    {
        $course=$this->input->post('course');
        $sem=$this->input->post('sem');
        $batch=$this->input->post('batch');
        $new_sem=$this->input->post('newsem');
        $results = $this->Student_model->get_all_student_by_cour_sem($course,$sem,$batch);
        $dep_id = [$results];
        //var_dump( $dep_id);die();
        $prodate = date('Y-m-d');
        $month = strtotime($prodate);
        $promonth = date('m',$month);


        $response_array = array();    // Declare an empty array to store all responses


        foreach($results  as  $val)
        {
            $dep_id = $val['student_id'];
            $db_date = $val['promote_date'];
            $db_month =  strtotime($db_date);
            $pro_month = date('m',$db_month);
            $cal = $pro_month +5;
            $data = array(
                'sem_id' =>$new_sem,
                'promote_date' =>$prodate
            );


            if($db_date == 0)
            {
                $id=$this->Student_model->update_semester($dep_id,$data);
                if($id)
                {
                    //$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Promote Semester Successfully... </div>');    

                    //redirect('Admin/display_promote_student');



                    $response_array[] = array(
                        'student_id' => $dep_id,    // you can use anything here according to your requirement
                        'msg' => '<div class="alert alert-success text-center">Promote Semester Successfully... </div>'
                    );

                }
                else
                {
                    //$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Promote Semester not Successfully... </div>');

                    //redirect('Admin/display_promote_student');



                    $response_array[] = array(
                        'student_id' => $dep_id,    // you can use anything here according to your requirement
                        'msg' => '<div class="alert alert-success text-center">Promote Semester not Successfully... </div>'
                    );
                }
            }
            elseif ($promonth == $cal)
            {
                $id=$this->Student_model->update_semester($dep_id,$data);
            }
            else
            {
                //$this->session->set_flashdata('msg','<div class="alert alert-success text-center">You can promote only after six months... </div>');

                //redirect('Admin/display_promote_student');



                $response_array[] = array(
                    'student_id' => $dep_id,    // you can use anything here according to your requirement
                    'msg' => '<div class="alert alert-success text-center">You can promote only after six months... </div>'
                );
            }
        }



        $this->session->set_flashdata('msg', $response_array);
        redirect('Admin/display_promote_student');
    }
}



由于我使用了一个数组用于flashdata,所以你必须相应地更改重定向页面上的代码。



一些指导
1-您应该使用codeigniter form_validation库。
2-每当要更新数据库中的多行时,请使用update_batch函数。