CodeIgniter Forums
[solved]Adding Dynamic Data to the View from the controller - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [solved]Adding Dynamic Data to the View from the controller (/showthread.php?tid=31423)



[solved]Adding Dynamic Data to the View from the controller - El Forum - 06-18-2010

[eluser]Unknown[/eluser]
Hi!

I need to add Data to the View.
I know i can make it with this:
Code:
$this->load->view('someview', $data);
I had used it sometimes, but now, i cant solve the problem...
Can i somehow watch, what data-s i have in the view?
So, i need to list all the users in my database.
i have this:
Code:
$usersdb=$this->User_model->getUsers();
then $userdb looks like this:
Code:
array(3) {
    [0]=> object(stdClass)#19 (2) {
        ["id"]=> "1"
        ["felhasznalonev"]=> "Koli"
    }
    [1]=> object(stdClass)#20 (2) {
        ["id"]=> string(1) "2"
        ["felhasznalonev"]=> string(6) "Jane"
    }
    [2]=> object(stdClass)#21 (2) {
        ["id"]=> string(1) "3"
        ["felhasznalonev"]=> string(4) "Mary"
    }
}
How can i get the user-name and the id-pairs in the view?
I tried it in a lot of way, but it never worked... Sad

Thanks:Koli


[solved]Adding Dynamic Data to the View from the controller - El Forum - 06-18-2010

[eluser]tim1965[/eluser]
you need to use foreach in your view and make you can see an example of this in the userguide for the database class section about returning data from queries


[solved]Adding Dynamic Data to the View from the controller - El Forum - 06-18-2010

[eluser]pickupman[/eluser]
Code:
$data['usersdb'] = $this->User_model->getUsers();

//In view
if(count($usersdb) > 0){

  foreach($usersdb->result() as $user){
    echo '<p>'.$user->id . ' ' .$user->felhasznalonev.'</p>';
  }
}



[solved]Adding Dynamic Data to the View from the controller - El Forum - 06-19-2010

[eluser]Unknown[/eluser]
Thanks!
With the ->result, it don't work, but without that it's working! Smile