How to display record based on their ID? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: How to display record based on their ID? (/showthread.php?tid=65735) |
How to display record based on their ID? - theromie - 07-18-2016 This is my index.php file
<a itemprop="title" style="text-transform: capitalize;color:#29aafe" href="<?=site_url('jobdetails/#'.$row->JPostID);?>"><?=$row->JTitle;?></a>
This is my model.php
public function getRowByJob($id){
$this->db->select('*');
$this->db->from('jobs');
$this->db->where('JPostID', $id);
$query = $this->db->get();
if($query->num_rows() > 0)
return $query;
}
This is my controller.php
public function jobdetails(){
$data = array();
$id = $this->input->get('id');
$data['jobdata'] = $this->mymodel->getRowByJob($id); // it is model method to fetch the record of that users having id = $id
$this->load->view('jobdetails',$data);
}
This is my jobdetails.php
<?php
foreach($jobdata as $row){?>
<div class="block-section box-item-details" itemscope itemtype="http://schema.org/JobPosting">
<h2 class="title" itemprop="title" style="text-transform: capitalize;"><?=$row->JTitle;?></h2>
</div>
RE: How to display record based on their ID? - projack89 - 07-18-2016 In your view.php <?php foreach($jobdata as $list):?> echo $list->field_name; <?php endforeach; ?> RE: How to display record based on their ID? - theromie - 07-18-2016 (07-18-2016, 01:20 AM)projack89 Wrote: In your view.php I did same but getting error Message: Invalid argument supplied for foreach() RE: How to display record based on their ID? - PaulD - 07-18-2016 That error is telling you $jobdata is not an array, so foreach cannot work. Before using a foreach you need to check it is set, not empty, and an array. RE: How to display record based on their ID? - pdthinh - 07-18-2016 (07-18-2016, 02:27 AM)theromie Wrote:(07-18-2016, 01:20 AM)projack89 Wrote: In your view.php In your model change the return statement to: PHP Code: if($query->num_rows() > 0) In your view check for the $jobdata is set Code: <?php if (isset($jobdata)): ?> |