1

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);
?>
8
  • any error in the view?? Commented Feb 26, 2016 at 8:54
  • empty page, instead of displaying array elements Commented Feb 26, 2016 at 9:06
  • check var_dump($data["results"]); in your controller Commented Feb 26, 2016 at 9:08
  • show me your model name Commented Feb 26, 2016 at 9:42
  • are you getting any error if yes than show me your error too. Commented Feb 26, 2016 at 9:43

1 Answer 1

1

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);
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.