Welcome Guest, Not a member yet? Register   Sign In
[solved] Message: "Undefined variable: data"
#1

[eluser]Jan_1[/eluser]
Hello together,
I getting ill by trying and searching in forums and documentations for hours... I do not get my MySQL-Data into my View.
I get a correct result using "print_r($data);". I started with MVC but after reducing everything to the problem I reduced also the model.
Seems I don't understand the basics. Could somebody give me some good hints?
Thanks a lot!!! Jan


Controller:
Code:
<?php
class Profil extends Controller {
    
    function Profil()
    {
         parent::Controller();
         $this->freakauth_light->check();
         $this->_container = $this->config->item('FAL_template_dir').'template/container';
    }
    function index(){ some simple code that works... }
    function contact()
    {
        $formdata['heading'] = 'Adress & Co';
        $formdata['page'] = $this->config->item('FAL_template_dir').'template/profil/contact';
        $this->load->vars($formdata);

        $sql = $this->db->query(" SELECT * FROM fa_user_profile
                                  WHERE id=".$this->db_session->userdata('id')."
                                  ");
        if ($sql->num_rows() > 0)
            { $data = $sql->row(); }
        print_r($data);
        $this->load->vars($data);
        $this->load->view($this->_container);
    }
}?>

View:
Code:
<table>
<tr><td width='100px'>Username:</td><td width='150px'><b>&lt;?=getUserName()?&gt;</b></td>
/*(Line 14->)*/     <td width='100px'>Street:</td><td width='150px'><b>&lt;?php echo $data->street; ?&gt;</b></td>
  </tr></table>
Result on webpage is " Street:"
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: data
Filename: profil/contact.php
Line Number: 14

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: profil/contact.php
Line Number: 14
#2

[eluser]xwero[/eluser]
The variables are extracted so you fetch them by the array key. in your case echo $street should do it.
#3

[eluser]Jan_1[/eluser]
Yes, that's it! Thank you!!!




Theme © iAndrew 2016 - Forum software by © MyBB