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


I need to add Data to the View.
I know i can make it with this:
$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:
then $userdb looks like this:
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


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

$data['usersdb'] = $this->User_model->getUsers();

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

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

With the ->result, it don't work, but without that it's working! Smile

Theme © iAndrew 2016 - Forum software by © MyBB