How to view all data based on link id in codeigniter

问题: I am new to codeigniter. I am getting values from database into jobs page. In jobs page I am showing only three columns from jobs table from database. I have a link button...

问题:

I am new to codeigniter. I am getting values from database into jobs page. In jobs page I am showing only three columns from jobs table from database. I have a link button as 'View More'. When user clicks on view-more link, then I want to show all job details based on it's id in viewjobs page.

How can I get id from jobs page to viewjobs page to display all data from jobs table from database? How can I get values in controller?

Please check my jobs controller code

class Careers extends CI_Controller {
  public function jobs()
  {   
    $this->load->database();  
    $this->load->model('xjobs');  
    $data['h']=$this->xjobs->xjobslist();  
    $this->load->view('jobs', $data);  
  } 
}

Here is my jobs.php code from view.

<table class="table table-hover table-striped jobtable">
  <thead style="background:#f4ae00; color:#fff; border-radius:5px 5px 0px 0px;">
    <tr>
      <th height="30" style="font-weight:400; font-size:18px;">Company Name</th>
      <th style="font-weight:400; font-size:18px;">Job Title</th>
      <th style="font-weight:400; font-size:18px;">Location</th>
      <th style="font-weight:400; font-size:18px;">View</th>
    </tr>
  </thead>
  <tbody>
<?php  
    foreach ($h->result() as $row)  
    {
?>
      <tr>
        <td height="60" style="padding-top:15px;"><?php echo $row->company; ?></td>
        <td style="padding-top:15px;"><?php echo $row->position; ?></td>
        <td style="padding-top:15px;"><?php echo $row->location; ?></td>
        <td style="padding-top:15px;">
          <a href='<?php echo base_url() ?>careers/viewjob?id=<?php echo $row->id; ?>&<?php echo $row->company; ?>&<?php echo $row->location; ?>' class='apply-btn'>View More</a>
        </td>  
      </tr>
<?php                                                                 
    }
?>
  </tbody>
</table>

回答1:

Use $row->id to get all the data from the controller

<td style="padding-top:15px;"><a href="<?= base_url('careers/viewjob/'. $row->id) ?>" class='apply-btn'>View More</a></td> 

Controller

public function viewjob($id){
 $this->load->model('xjobs');  
 $data['detail']=$this->xjobs->jobdetail($id);  
 $this->load->view('filename', $data); 
}

Model

public function  jobdetail($id){
    return $this->db->get_where('table', ['column' => $id])->row();
}
  • 发表于 2019-03-02 14:47
  • 阅读 ( 164 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除