mysql - 根据 codeigniter 中的 id 在 View 中显示表值

标签 mysql codeigniter

我的申请中有一个可查看候选人详细信息的表格。 其中我提供了一个称为预约面试的按钮。 因此,当我单击按钮时,它会将页面重定向到候选流程页面,网址中包含candidate_id和user_id。

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

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

这是我的观点:

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

Controller :

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

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

提前致谢。

最佳答案

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

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

希望能解决您的问题

关于mysql - 根据 codeigniter 中的 id 在 View 中显示表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42524163/

相关文章:

javascript - 当按钮被 ajax 加载时触发事件

mysql - 使用连接在 MySQL 中转换货币

mysql - 使用 concat 插入 MySQL 查询

mysql - 合并 2 个表

codeigniter - Laravel 是否重新生成 session ID? (与 CodeIgniter 相比)

php codeigniter 不更新变量到 mysql

php - 获取查询中带有限制的所有行

php - 阅读 SELECT LAST_INSERT_ID(),这似乎产生了一个数组

php - 在一台服务器上创建Mysql主机并从另一台服务器访问数据库?

php - 在 codeigniter 项目之间共享 session 存储