So I have this line of code in my controller:
$this->load->view('sampleview',$result);
So when I go into my view and try to echo
result, either by foreach
or directly writing
print_r($result);
it shows an error that it is an undefined variable.
But when I put the print_r($result);
on my controller like this below:
function show()
{
$this->load->view('sampleview',$result);
print_r($result);
}
It would print on my sampleview
page where I was redirected. I’m confused why this is happening.
EDIT
The whole controller would be: I have another view which I click an anchor tag with segment(3)
as an id. Then I query that id to my model then pass it to another view for display.
$id = $this->uri->segment(3);
$result = $this->model->show($recipe_id);
if($result!=null)
{
$this->load->view('Admin_recipe_edit',$result);
}