Welcome Guest, Not a member yet? Register   Sign In
Noob! Accessing a variable from an array
#1

[eluser]trickymh[/eluser]
Hello,

I apologise if this has been covered before. I have searched, but only found one similar question, and the fix didn't work for me.

All I want to do is retrieve the value of a field, and use it in a view.

My Controller:

Code:
function index()
    {
        $this->load->model('data_model');
        $data['resources'] = $this->data_model->get_resource(); // get info from table
        $data['no_props'] = $this->db->count_all('resources'); // count no. of rows in table
        $this->load->view('home_view', $data);
    }

My model code:

Code:
function get_resource()
    {
        $results = $this->db->get('resources')->result();
        return $results;
    }

And my view code (well, the important bit)

Code:
<div>&lt;?php echo $results->name;?&gt;</div>

where 'name' is the name of the field. For testing's sake there is only one row in the 'resources' table.

I get the following errors:
undefined variable: results
trying to get property of non-object

I have tried so many different syntaxes and ways of doing this. I'm going mental hehe.

Thanks for any help


Messages In This Thread
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 05:13 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 05:56 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:01 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:03 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:04 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:18 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:23 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:25 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:28 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:32 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:38 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 06:47 AM
Noob! Accessing a variable from an array - by El Forum - 04-10-2010, 07:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB