【问题标题】:display table values in view depending on id in codeigniter根据 codeigniter 中的 id 在视图中显示表值
【发布时间】:2017-03-01 15:43:38
【问题描述】:

我的申请中有一个查看候选人详细信息表。 在那我给了一个按钮,叫做预定面试。 因此,当我单击按钮时,它会将页面重定向到候选进程页面,其中包含 url 中的候选 ID 和用户 ID。

在 Candidate_process 页面中,我有一个包含一些详细信息的表单,在该表单下,我将数据库中的所有记录显示在数据表中。

我只想显示特定候选人的记录。我不想显示所有记录。

这是我的看法:

<form method="post"  action="" id="form">
 <b>Date </b>:<input type="text" name="date" id="date"><br><br>
    <input type="hidden" name="candidate_id" value="<?php echo $getCandidate['candidate_id']; ?>">
    <input type="hidden" name="user_id" value="<?php echo $getCandidate['user_id']; ?>">
    <div class="form-group">
        <label><b>Select Interview Type:</b></label>
            <select  class="form-control"  id="interview_type_id" name="interview_type_id" >
                <option value="" disabled selected>Interview Type</option>
                    <?php foreach($interviewtype as $rows) { ?>
                        <option value="<?php echo $rows->interview_type_id?>"><?php echo ucfirst($rows->interview_type_name)?></option>
                    <?php } ?>
            </select>
    </div><br>
    <div class="form-group">
    <label><b>Select Status:</b></label>
        <select  class="form-control"  id="status_type_id" name="status_type_id" >
            <option value="" disabled selected>Status Type</option>
                <?php foreach($statustype as $rows) { ?>
                    <option value="<?php echo $rows->status_type_id?>"><?php echo ucfirst($rows->status)?></option>
                <?php } ?>
        </select>
    </div><br>      
    <button type="submit"  name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>
    <button type="submit" id="submit" name="submit" class="btn btn-primary" value="schedule" onclick="ScheduleNextRound();">Schedule Next Round</button><br></br> 
</form>
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
  <h3>Reports</h3>
</section>
<!-- Main content -->
<section class="content">
  <div class="row">
         <div class="col-xs-12">
         <div class="box">
         <div class="box-body">
     <table id="example1" class="table table-bordered table-hover">
            <thead>
              <tr>
              <th>Interview Date</th>
               <th>Candidate</th> 
              <th>interview</th>
              <th>status</th>
              <th>Vendor</th>
            </tr>
            </thead>
             <?php foreach ($view_candidates as $idata){ ?>
              <tbody>
               <tr id="domain<?php echo $idata->candidate_seletion_id;?>">
                    <td><?php echo $idata->date;?></td>
                    <td><?php echo $idata->f_name;?></td>  
                     <td><?php echo $idata->interview_type_name;?></td>
                     <td><?php echo $idata->status;?></td>
                     <td><?php echo $idata->first_name;?></td>
             </tr>
            <?php } ?>
        </tbody>
    </table>
  </div>
  <!-- /.box-body -->
  </div>
  <!-- /.box -->
  </div>
  </div>
  </section>
   </div>

控制器:

function candidate_process($candidateid,$userid){ 
    $data["msg"]="";
    $this->load->model('CandidateModel');
    $data['statustype']=$this->CandidateModel->getstatustypes();
    $data['interviewtype']=$this->CandidateModel->getinterviewtypes();
    $data['candidate']=$this->CandidateModel->getcandidates();
    $data['usertype']=$this->CandidateModel->getvendors();
    $data['getCandidate'] = $this->CandidateModel->get_candidate_detail($candidateid);
    $data['view_candidates'] = $this->CandidateModel->getcandidateselection();//this is my table view
    if($this->input->post('submit')=="submit"){ 
      $this->CandidateModel->add_candidate_selection($this->input->post());
      redirect(base_url('Candidate/view_candidate_selection'));
    }
 $this->load->view('Candidates/candidate_process',$data);
}

模型1:

 public function add_candidate_selection($data){

       $data=array(
            'candidate_id'=>$this->input->post('candidate_id'),
            'user_id'=>$this->input->post('user_id'),
            'status_type_id'=>$this->input->post('status_type_id'),
            'interview_type_id'=>$this->input->post('interview_type_id'),
            'date'=>$this->input->post('date')
        );
    $this->db->insert('candidate_selection', $data);
    //print_r($data);
    }

模型2:

 public function getcandidateselection(){
         $this->db->select('*');
         $this->db->from('candidate_selection');
         $this->db-   >join('candidates_details','candidates_details.candidate_id=candidate_selection.candidate_id');
         $this->db->join('interview_types','interview_types.interview_type_id=candidate_selection.interview_type_id');
         $this->db->join('status_types','status_types.status_type_id=candidate_selection.status_type_id');
         $this->db->join('users','users.user_id=candidate_selection.user_id');
         $query = $this->db->get();
         //echo $this->db->last_query();
         return $query->result();
    }

任何人都可以帮助我如何做到这一点..

提前致谢。

【问题讨论】:

    标签: mysql codeigniter


    【解决方案1】:

    在你的模型函数中替换以下代码

    function getcandidateselection($candidateid) 
    { 
        $this->db->join('candidate_selection as cs','cs.candidate_id = cd.candidate_id');
        $this->db->join('status_types as st','st.status_type_id = cs.status_type_id');
        $this->db->where('cd.candidate_id',$candidateid);
        $q = $this->db->get('candidates_details as cd');
        return $q->result(); 
    }
    

    希望它能解决你的问题

    【讨论】:

      猜你喜欢
      • 2019-09-10
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多