CodeIgniter Forums
Array value - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Array value (/thread-20658.html)



Array value - El Forum - 07-17-2009

[eluser]Ninja[/eluser]
I have an array that gets all clients ids from the client table as the index and companynames from the company table as the value but i need to display only the value (.ie the companyname for each client)

Controller
Code:
foreach ($parents->all as $parent)
        {
            $id = $parent->parent_client;
            $parent->company->get('id, companyname');
            $name = $parent->company->companyname;
        
            $data['parent'][$id] = $name;
        }

View
Code:
<?=$parent ?>
This displays 'Array' (naturally) i tried using another foreach in the view but that displayed all the clients

i know the array is fine because i used a print_r to check it.

How can i display only the value for each element in the array?
Please help..


Array value - El Forum - 07-17-2009

[eluser]darkhouse[/eluser]
Well it looks like you shouldn't be having any trouble with that new $parent array. But, why don't you just do this in your controller:

Code:
$data['parents'] = $parents->all;

Then in your view you can do this:

Code:
foreach($parents as $parent){
   echo $parent->company->companyname;
}



Array value - El Forum - 07-17-2009

[eluser]Ninja[/eluser]
Thanx for your assistance
Its not working it keeps throwing a 'Trying to get property of non-object' notice