0

I have a query like this :

    $this->db->select('shop_users.user_id');
    $this->db->select('users.*');
    $this->db->from('shop_users');
    $this->db->join('users' , 'users.id = shop_users.user_id' );
    $this->db->where('shop_users.shop_id',$gets['shop_id']);
    $user = $this->db->get()->result();

    $data['user'] = $user;

    var_dump($user);

    return;

content of var_dump() is :

> array(1) { [0]=> object(stdClass)#76 (29) { ["user_id"]=> string(5)
> "33691" ["id"]=> string(5) "33691" ["username"]=> string(16)
> "" ["password"]=> string(32)
> "" ["name"]=> string(8) "سوده"
> ["family"]=> string(17) "محمد کاشی" ["email"]=> string(21)
> "" ["avatar"]=> string(11) "default.gif"
> ["status"]=> string(1) "1" ["submit_date"]=> string(19) "2015-12-26
> 13:17:20" ["last_activity"]=> string(1) "0" ["activecode"]=> string(1)
> "0" ["submit_ip"]=> string(0) "" ["city"]=> string(1) "1" ["zone"]=>
> string(1) "0" ["city_name"]=> string(1) " " ["phone"]=> string(20)
> "" ["bankAcount"]=> string(13) ""
> ["bankCart"]=> string(1) " " ["bank"]=> string(1) " " ["admin_seen"]=>
> string(1) "1" ["gender"]=> string(1) " " ["finance"]=> string(1) "0"
> ["coupons"]=> string(1) "0" ["shaba"]=> string(1) " " ["ref"]=>
> string(1) "0" ["done"]=> string(1) "0" ["hasmobile"]=> string(1) "0" }
> }

now, how can I fetch user_id ?

I've test below codes but them return null:

$user->user_id;
$user['user_id'];
1
  • Use echo "<pre>"; print_r($user); for formatted output instead of using var_dump(). Commented Dec 26, 2015 at 13:29

2 Answers 2

1
$user[0]['user_id'];

or

$user[0]->user_id;

You have to access to first element of your array because it is your array of returned values. (array in array)

Sign up to request clarification or add additional context in comments.

2 Comments

What happened when no data returned i mean no output for query? table empty? Undefined error occured.
So then add a IF for array size :) if (empty($user[0])){echo 'empty array';}
1

You get a array from this query. You can get first item at frist and than get attrs of the item.

if($user && count($user)>0){
  echo $user[0]->user_id;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.