1

I'm working on a view that shows me the data from the database.

but the result is

Severity: Notice

Message: Undefined variable: data

Filename: mentee/index.php

UserModel.php

<?php

class UserModel extends CI_Model{

    public function __construct(){
        parent::__construct();
    }


    public function userProfile($nim){
        $this->db->where('userNIM',$nim);
        $query= $this->db->get('msuser');
        return $query->result();
    }

}

MainController.php

public function indexMentee()
    {
        $this->load->model('UserModel');
        $userID=$this->session->userdata("userNIM");
        $data['data'] = $this->UserModel->userProfile($userID);
        $this->load->view('mentee/index', array('data' => $data));

     }

View

<?php 
die(var_dump($data));
if(is_array($data)){
    foreach ($data as $profile): 

?>
        <div class="header-content">
            <div class="header-content-inner">
                <h1>Learning Center</h1>
                <hr>    
                <h3> Welcome,<?php echo $profile->userName ?></h3>                                
            </div>
        </div>
<?php
    endforeach;
}
?>

Please help me..Thanks a lot!

2 Answers 2

2

Instead of passing array('data' => $data)); just pass $data to the view.

Sign up to request clarification or add additional context in comments.

Comments

0

First print session data. If session data present then pass data to view page

$data['details'] = $this->UserModel->userProfile($userID);
$this->load->view('mentee/index', $data);

And print print_r($details); on your view page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.