My DB has 2 rows of values : Test2 campaign & premium dove
view page
foreach ($estedit as $estrow) {
//print_r($estrow);
echo $estrow->name;
}
The above code shows these 2 values at the bottom as in the below linked image, but it displays error Trying to get property 'name' of non-object.
Error Screenshot:
https://i.sstatic.net/g7wtz.png
print_r($estrow); inside the foreach loop shows the below given data:
stdClass Object ( [est_id] => 3 [name] => Test2 campaign ) stdClass Object ( [est_id] => 1 [name] => premium dove ).
Accessing the name field as $estrow->name shows the error Illegal string offset 'name'.
What am i doing wrong?
How can i access the name field here ?
Controller
$estedit[] = '';
foreach ($est_id as $item) {
$estedit[] = $this->Report->get_estedit($item);
$estlineedit[] = $this->Report->get_estline_edit($item);
}
$data['estedit'] = $estedit;
$data['estlineedit'] = $estlineedit;
$data['date'] = $date;
$this->load->view('reports/download_report_view', $data);
$esteditsomewhere insideforeachloopprint_r(null)orprint_r(false)for example result in absolutely no visible output - so if you had more items in$esteditthan you thought maybe, and one of them was null or false, that would absolutely explain what you are seeing.var_dumpinstead ofprint_r, that is a better debug tool. And use it to check what$esteditcontains, instead of trying to figure out what is going on only inside the loop.