【问题标题】:How to promote a batch of students from a semester to another? [closed]如何将一批学生从一个学期提升到另一个学期? [关闭]
【发布时间】:2023-03-17 14:35:02
【问题描述】:

我想从第一学期提升一批学生到第二学期。

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

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');
          }
        }
      }
    }
我有表学生,课程,学期,批次

-------型号----------

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

--------------浏览量---------- ---

promote_student

<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>

列出_promote_students

<div class="container">
 <a  href="<?php echo base_url('Admin/display_promote_student');?>" class="btn btn-warning btn-flat margin pull-right">Previous</a>
 <div class="col-md-10 col-md-offset-1">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3>Student List</h3>
            </div> 
            <div class="panel-body">
		  <table id="example1" class="table table-bordered table-striped">
                <thead>
                <tr>
                  <th>Serial no</th>
				  <th>Student Name</th>
                  <th>Course</th>
				  <th>Semester</th> 
				  <th>Batch</th>
                </tr>
                </thead>
				  <tbody>
                  <?php 
          $i=1;		 
         foreach ($promote as $row)  
         {   
            ?>
                <tr>
				  <td><?php echo $i++;?></td>
				  <td><?php echo $row['stud_name'];?></td>
				  <td><?php echo $row['c_name'];?></td>
				  <td><?php echo $row['sem_code'];?></td>
				  <td><?php echo $row['batch_year'];?></td>	
				</tr>
	<?php }  
         ?>  
            </tbody>
            </table>
            <?php $attributes = array("name" => "update");
        echo form_open("Admin/promote_semester_processing", $attributes);?>
		 <input type="hidden" value="<?php echo $course;?>" name="course"/>
		  <input type="hidden" value="<?php echo $sem;?>" name="sem"/>
		   <input type="hidden" value="<?php echo $batch;?>" name="batch"/>
		    <div class="form-group">
                    <label>Semester</label>
                     <select class="form-control" name="newsem" required data-placeholder="Semester">
                      <option>--Semester--</option>
                      <option value="1">s1</option>
                      <option value="2">s2</option>
                      <option value="3">s3</option>
                      <option value="4">s4</option>
                      <option value="5">s5</option>
                      <option value="6">s6</option>
                    </select>
        </div>
		   <button name="save" type="submit" class="btn btn-warning" >Promote Semester</button>
		<?php  echo form_close(); ?>
        </div>
      </div>
    </div>
  </div>

只有一名学生使用此代码获得晋升。但我想提拔一批学生进入下学期。我该怎么做?

请尽早帮助我。

【问题讨论】:

  • 我认为这是很多代码。你能只发布最相关的行吗?
  • 提示询问运行代码sn-ps for javascript, html, css not php 如果你需要添加代码你可以这样添加meta.stackexchange.com/questions/22186/…

标签: php html css mysql codeigniter


【解决方案1】:

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

Codeigniter update_batch function link

代码中的问题:- 问题出在控制器的 promote_semester_processing() 函数中。在 foreach 循环 中,只要第一个用户的学期成功更新,那么您在设置 flash 数据后使用 redirect('Admin/display_promote_student'); $this ->session->set_flashdata('msg','Promote Semester Successfully...'); 刷新页面,因此下一个更新查询永远不会执行。



在您发表评论后更新了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 函数。

【讨论】:

  • 而不是重定向('Admin/display_promote_student'); flashdata 之后将设置什么。我删除了重定向代码,输出学生正在推广,但将显示一个普通页面。
  • @ZelahAsher 根据您当前的实现,您可以在 foreach 循环之前声明一个空数组,然后在 foreach 循环内用消息填充该数组(不要在这点)。在foreach循环完成后,您可以使用新创建的数组设置flashdata,然后简单地重定向。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 2022-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多