Message trying to get property of non-object inside foreach in codeigniter

I am getting my query output in the model and sending to controller If I check the data in the controller like print_r($result);
I am getting the output from my Model and My output is

stdClass Object
    [membership_id] => 11
    [member_id] => 10
    [customer_id] =>21
    [membership_approve] => 1
    [membership_status] => 1
    [profile_pic] => 
    [first_name] => Juvin
    [middle_name] => kumar
    [last_name] => choudhary
    [email] =>
    [dob] => 2018-07-01
    [phone] => 01236541254
    [is_Approved] => 1

Model code is

if ($result) {
  foreach($result as $result_set ){
     if($result_set->membership_status == 1)
            ->join('members','members.member_id = membership_details.member_id')
                ->where('membership_details.membership_status', 1)

          return $result2;
        return 0;

  else{echo "Not working";}

Now I am on the controller. I am passing the output in the foreach but when I check $row->phone then it's showing me

Message: Trying to get property of non-object


    $arr_result2 = array();
    if (count($result) > 0)
            print_r($result);// It's displaying the same output which I aaded in the question.
            foreach($result as $row){
                print_r($row->customer_id);// not getting customer id
                $arr_result2[] = array(
                    "profile_pic" => $row->profile_pic,
                    "name" => $row->first_name.' ' .$row->last_name,
                    "phone" => $row->phone
         else{echo "No data availble";}
        echo json_encode($arr_result2);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s