PHP data array variable not defined in view

elrosb8hat

New Member
I am using codeIgniter and I am trying to pass an array of data. I have written like this:\[code\]$data['username']="Dumbo";\[/code\]I also wrote this:\[code\]$data['shouts']=$this->Musers->getShout(); // retrieve data from table\[/code\]Then I write: \[code\]$this->load->view("welcome_message", $data);\[/code\]In view page, I wrote:\[code\] <?php echo $username; foreach ($shouts as $shout) { echo $shout->shout; echo '<br>'; echo $shout->timeStamp; } ?> \[/code\]Problem is that while the view did retrieve data from table and display results in view page, an error came up for $data['username'] saying, "Undefined variable: username"Why is that? The $data['username'] is already defined! Or what did I do wrong?
 
Back
Top