Reputation: 3150
I am new to CodeIgniter. In the model, I have the following code:
public function get_all_subjects()
{
return $this->db->get('subjects');
}
In the controller, I have:
public function index()
{
$this->load->model('subjects');
$data['content'] = $this->subjects->get_all_subjects();
$this->load->view('home', $data);
}
I am trying to get the values in the view:
foreach($content as $val)
{
echo $val['subject']; //i am getting error, Message: Undefined index: subject
}
The fields in the subjects
table are subject_id
and subject
.
I am getting this error message:
Undefined index: subject
Upvotes: 1
Views: 64
Reputation: 664
public function get_all_subjects()
{
return $this->db->get('subjects')->result_array();
}
You are not returning result from your query. You have just run the query.
Upvotes: 7