Welcome Guest, Not a member yet? Register   Sign In
[solved]Adding Dynamic Data to the View from the controller
#1

[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
#2

[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
#3

[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>';
  }
}
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB