Welcome Guest, Not a member yet? Register   Sign In
Use property from database in controller
#1

[eluser]Christophe28[/eluser]
Hi,

I have some stuff from the database which I put in $data['user'] and then pass it as $data to the view file. However I'd like to use one thing (id) to get something from another model (table)

What I have for now:
Code:
function get_user_info($username) {
        
        // creating a condition for the query
        $this->db->where('username', $username);
        
        // executing the query
        $sql = $this->db->get('users');
        
        // put the result in a variable
        $user = $sql->row();
        
        // returning a row object
        return $user;

This result comes in the controller:
Code:
$data['user'] = $this->users_model->get_user_info($username);

But I would like to use something out $data['user'] in the controller itself ...

How can I get this property?

echo $user->id; (didn't work)
echo $data['user']['id']; (didn't work either)

Thanks for any help!

Christophe
#2

[eluser]Buso[/eluser]
Code:
echo $data['user']->id
#3

[eluser]Christophe28[/eluser]
Thx!

(why didn't I figured that out. True summer student here :-)
#4

[eluser]brycmills[/eluser]
Very helpful.




Theme © iAndrew 2016 - Forum software by © MyBB