2017-07-01 19 views
-1

我想推廣一批學生從第一學期到第二學期。如何將一批學生從一學期推廣到另一學期?

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

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

------------------------- views ------------------- -----

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"> 
 
\t \t \t \t <select class="form-control" name="course" required> 
 
\t \t \t \t <option>--Choose a Course--</option> 
 
        <?php 
 
    foreach($course as $row) 
 
    { 
 
     echo '<option value="'.$row->course_id.'">'.$row->c_name.'</option>'; 
 
    }?> 
 
\t \t \t \t </select> 
 
       <span class="text-danger"><?php echo form_error('course'); ?></span> 
 
        </div> 
 
\t \t \t \t  </div> 
 
\t \t \t 
 
      \t <div class="form-group has-feedback"> 
 
        <label for="semester" class="col-sm-2 control-label" placeholder="">Semester</label> 
 
        <div class="col-sm-6"> 
 
\t \t \t \t  
 
        <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>'; 
 
    }?> 
 
\t \t \t  </select> 
 
       <span class="text-danger"><?php echo form_error('semester'); ?></span> 
 
        </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t  <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>

List_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"> 
 
\t \t <table id="example1" class="table table-bordered table-striped"> 
 
       <thead> 
 
       <tr> 
 
        <th>Serial no</th> 
 
\t \t \t \t <th>Student Name</th> 
 
        <th>Course</th> 
 
\t \t \t \t <th>Semester</th> 
 
\t \t \t \t <th>Batch</th> 
 
       </tr> 
 
       </thead> 
 
\t \t \t \t <tbody> 
 
        <?php 
 
      $i=1; \t \t 
 
     foreach ($promote as $row) 
 
     { 
 
      ?> 
 
       <tr> 
 
\t \t \t \t <td><?php echo $i++;?></td> 
 
\t \t \t \t <td><?php echo $row['stud_name'];?></td> 
 
\t \t \t \t <td><?php echo $row['c_name'];?></td> 
 
\t \t \t \t <td><?php echo $row['sem_code'];?></td> 
 
\t \t \t \t <td><?php echo $row['batch_year'];?></td> \t 
 
\t \t \t \t </tr> 
 
\t <?php } 
 
     ?> 
 
      </tbody> 
 
      </table> 
 
      <?php $attributes = array("name" => "update"); 
 
     echo form_open("Admin/promote_semester_processing", $attributes);?> 
 
\t \t <input type="hidden" value="<?php echo $course;?>" name="course"/> 
 
\t \t <input type="hidden" value="<?php echo $sem;?>" name="sem"/> 
 
\t \t <input type="hidden" value="<?php echo $batch;?>" name="batch"/> 
 
\t \t  <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> 
 
\t \t <button name="save" type="submit" class="btn btn-warning" >Promote Semester</button> 
 
\t \t <?php echo form_close(); ?> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div>

只有一個學生正在使用此代碼升遷。但是我想把一批學生提升到下一個學期。我怎麼做?

請儘早幫助我。

+0

我認爲這是很重要的代碼。你能發佈最相關的行嗎? –

+0

提示提問javascript,html,css不是php的運行代碼片段如果您需要添加代碼,您可以通過這種方式添加代碼https://meta.stackexchange.com/questions/22186/how-do-i-format-我的代碼塊 – user4419336

回答

0

現在你是一個使用循環更新的學生之一,但你應該使用CodeIgniter的update_batch函數模型的update_semester內($ dep_id,$數據)功能。您還必須傳遞$ data參數中的所有學生數據。在你的代碼

Codeigniter update_batch function link

問題: - 問題是在您的控制器的promote_semester_processing()功能。在foreach循環每當第一個用戶的學期更新成功,那麼您正在使用重定向('Admin/display_promote_student');設置閃存數據後$ this-> session-> set_flashdata('msg','Promote Semester Successfully ...');刷新頁面,因此下一次更新查詢將永遠不會執行。您的評論

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數組,所以經過



更新promote_semester_processing()函數,你必須相應地改變重定向網頁上的代碼。



一些指導
1-你應該笨form_validation庫使用。
2-每當您想要更新數據庫中的多行時使用update_batch函數。

+0

而不是重定向('Admin/display_promote_student'); flashdata後面會設置什麼。我刪除重定向代碼,輸出學生正在推廣,但將顯示一個普通頁面。 –

+0

@ZelahAsher根據你當前的實現,你可以在foreach循環之前聲明一個空數組,然後用foreach循環中的消息填充這個數組(在這一點上不要使用「flashdata」和「重定向」)。 foreach循環完成後,您可以用新創建的數組設置flashdata,然後重定向。 –