使用codeigniter仅在特定班级列表中添加学生

时间:2016-03-22 11:41:20

标签: codeigniter

我在查看我选择的课程列表并添加学生时遇到问题但是当我选择其他课程时,它也会出现/查看我在上一课程中选择

这里我选择了我选择的课程 enter image description here

这是我选择的课程页面,然后我添加了学生 enter image description here

但是当我选择另一个班级时,它也会出现在学生身上 enter image description here enter image description here

这是我的控制器:

 public function viewspecificclass($id)
{
   if($this->session->userdata('logged_in'))
    {
 $this->output->set_header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
 $this->output->set_header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0');
 $this->output->set_header('Cache-Control: post-check=0, pre-check=0', FALSE);
 $this->output->set_header('Pragma: no-cache');
       $session_data = $this->session->userdata('logged_in');

       $data['Username'] = $session_data['Username'];
       $row=$this->model_adminlogin->getonerowclass($id);
       $data['r']=$row;
       $data['classid'] = $id;

   $this->load->view('individualviewclass',$data);
    } else{
        redirect('welcome', 'refresh');
    }
    if((!isset($session_data) || $session_data !=TRUE)) {

        redirect('welcome', 'refresh');
    }


}

    public function addstudentnow($classid, $studentid){

           $data= array(

                'ClassId'=>$classid,
               'Id'=> $studentid
        );
          $this->db->insert('enroll',$data);

         $this->session->set_flashdata('category_success', 'Successfully Add!');
         redirect('enrollment/viewspecificclass ');

}

这是我的模特:

  function statusofenrollment(){
        
        
        $this->db->select('*');
 $this->db->from('studentinformation');
 $this->db->join('statusofenrollment', 'statusofenrollment.Id = studentinformation.Id', 'left');
 
  
    

  
$query = $this->db->get();
return $query->result();
    }
     function studentinclasslist(){
        
        
        $this->db->select('*');
 $this->db->from('statusofenrollment');
 $this->db->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right');
  $this->db->join('enroll', 'enroll.Id = studentinformation.Id', 'right');
   
$query = $this->db->get();
return $query->result();
    }

这是视图:

        <div class="z table-responsive">

          <table class=" table table-striped ">

                 <thead>
                         <tr>

                             <th class="text-center">LRN</th>
                               <th class="text-center">First name</th>
                               <th class="text-center"> Middle name</th>
                               <th class="text-center">Last name</th>
                                 <th class="text-center">Gender</th>
                                   <th class="text-center">Status of Enrollment</th>
                           <th class="text-center"> </th>

                       </tr>
                  </thead>

                  <?php


                foreach($this->model_adminlogin->studentinclasslist() as $row){

                        ?>





      <tr>


              <td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
               <td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
               <td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>

                         <td class="text-capitalize text-center">

                         </td>

     </tr>


              <?php
          }




                     ?>
          </table>
      </div>







       <div id="myModalpick" class="modal fade" role="dialog">

<!-- Modal content-->
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title text-center">Student Status</h4>
  </div>
  <div class="modal-body">

      <div class="z table-responsive">

          <table class=" table table-striped ">

                 <thead>
                         <tr>

                             <th class="text-center">LRN</th>
                               <th class="text-center">First name</th>
                               <th class="text-center"> Middle name</th>
                               <th class="text-center">Last name</th>
                                 <th class="text-center">Gender</th>
                                   <th class="text-center">Status of Enrollment</th>
                           <th class="text-center"> </th>

                       </tr>
                  </thead>

                  <?php


                foreach($this->model_adminlogin->statusofenrollment() as $row){

                        ?>





      <tr>


              <td class="text-capitalize text-center"><?php echo $row->Idnumber ?></td>
               <td class="text-capitalize text-center"><?php echo $row -> Firstname ?></td>
               <td class="text-capitalize text-center"><?php echo $row->Middlename ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Lastname ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Sex ?></td>
                <td class="text-capitalize text-center"><?php echo $row->Statusofenrollment ?></td>

                         <td class="text-capitalize text-center">
                             <a href="<?php echo site_url('enrollment/addstudentnow/'.$classid. '/'.$row->Idnumber ) ?>" class="btn btn-info"  type="submit" role="button"> Add To Class List </a>

                         </td>

     </tr>


              <?php
          }




                     ?>
          </table>
      </div>
   </div>

  <div class="modal-footer"> 
        <button type="submit" class="btn btn-default" >Ok</button>
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
  </div> 
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

因为您的代码完全没有组织,所以很难帮助您 - 但我会试一试

首先在你的模型中使用函数studenClassList你可以从特定的类中传递一个id,因为其他明智的你可以接受所有类的学生的任何请求 - 像这样改变你的模型< / p>

function studentinclasslist($classId){

    $query = $this->db
        ->select('studentinformation.*')
        ->from('statusofenrollment')
        ->join('studentinformation', 'studentinformation.Id = statusofenrollment.Id', 'right')
        ->join('enroll', 'enroll.Id = studentinformation.Id', 'right')
        ->where("class.Id",$classId)
        ->get();

    return $query->result();
}

请注意,您必须更改where构造实际的class.Id字段,因为我无法看到它在哪里

然后在您的视图中将ID传递给您的模型函数

foreach($this->model_adminlogin->studentinclasslist($classId) as $row){

但无论如何我必须说,在我看来,CI在你的视图中使用模型并不是一个好主意,因为控制器应该将准备好的模型数据传递给视图