Welcome Guest, Not a member yet? Register   Sign In
How to display record based on their ID?
#1

(This post was last modified: 07-18-2016, 02:31 AM by theromie.)

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>
theromie
Reply
#2

In your view.php

<?php foreach($jobdata as $list):?>
echo $list->field_name;
<?php endforeach; ?>
Reply
#3

(07-18-2016, 01:20 AM)projack89 Wrote: In your view.php

<?php foreach($jobdata as $list):?>
           echo $list->field_name;
<?php endforeach; ?>

I did same but getting error 
Message: Invalid argument supplied for foreach()
theromie
Reply
#4

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.
Reply
#5

(This post was last modified: 07-18-2016, 09:53 AM by pdthinh.)

(07-18-2016, 02:27 AM)theromie Wrote:
(07-18-2016, 01:20 AM)projack89 Wrote: In your view.php

<?php foreach($jobdata as $list):?>
           echo $list->field_name;
<?php endforeach; ?>

I did same but getting error 
Message: Invalid argument supplied for foreach()

In your model change the return statement to:
PHP Code:
if($query->num_rows() > 0)
    return 
$query->result();
else
    return 
NULL

In your view check for the $jobdata is set
Code:
<?php if (isset($jobdata)): ?>
   <?php foreach ($jobdata as $row): ?>
       ...
   <?php endforeach ?>
<?php endif ?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB