Reputation: 979
All I want is to get some place_ids from db, put them in array and echo that array in view. Could you please check the code below and help me to find the mistake. I think the problem is in view part.
Model:
$this->db->select('place_id');
$this->db->from('table');
$this->db->where('ses_id', $ses_id);
$query = $this->db->get();
if ($query && $query->num_rows() > 0) {
return $query->result_array();
}
else {return false;}
Controller:
$ses_id = $this->uri->segment(3);
$data["results"] = $this->mymodel->did_get($ses_id);
$this->load->view("my_view", $data);
View:
<?php
$place_id = array();
foreach($results as $row){
$place_id[] = $row['place_id'];
}
print_r($place_id);
?>
Upvotes: 1
Views: 3487
Reputation: 1050
checking the $results is empty or not
<?php
$place_id = array();
if(!empty($results)
{
foreach($results as $row)
{
$place_id[] = $row['place_id'];
}
}else
{ echo "no data found";}
print_r($place_id);
?>
Upvotes: 1