Welcome Guest, Not a member yet? Register   Sign In
Single value return "Array to string conversion?"
#1

[eluser]Sky Warden[/eluser]
Hi everyone. I'm having a small problem with my data. I have this model :

Code:
function get_user($user_id){
    
        $this->db->select('username');
        $this->db->from('users');
        $this->db->where('id', $user_id);
        
        $query = $this->db->get();
        
        #echo $query->num_rows();
        
        return $query->result();
    }

Then I try to get the data like this :

Code:
$uploader = $this->user_model->get_user($user_id);
echo 'by '.$uploader;

That $uploader becomes an array, so I can't echo it directly. My question is, isn't my query result just a single value? The username and user_id is unique. I just select the username by the user_id. In the database, for example, I have user "Sky Warden" with id.1. Therefore, since the id is unique (primary key) shouldn't $uploader just contains "Sky Warden?"

Does every data fetched from query, no matter the value, is formatted as an array? Then how can I use it just to print "Sky Warden" because I don't know the element. I've tried echo $uploader['username'] but it returns undefined index, so I guess it's not the element. So...help me please?

P.S. I've tried the num_rows() and there's only just one matching value.


Messages In This Thread
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:13 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:35 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:45 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 03:52 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 04:33 AM
Single value return "Array to string conversion?" - by El Forum - 03-22-2013, 07:09 PM
Single value return "Array to string conversion?" - by El Forum - 03-23-2013, 10:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB