php - loop through facebook friends to find matches in database, facebook api -
i have made login facebook adds user database if haven't been added yet. want show other facebook friends (of current user signed up) have signed app well.. trying looping through facebook friends using $this->facebook->api('/me/friends') , finding matches in database (by id) , storing in array sent view (code igniter)
but far havent been able loop through users friends easily. keeps coming with,
undefined index: id
here code:
dashboard controller:
public function index() { if ($this->user) { try{ $data['user_profile'] = $this->facebook->api('/me'); $data['friends_list'] = $this->users_model->get_friends_on_drimmly($this->facebook->api('/me/friends')); } catch(facebookapiexception $e) { error_log($e); $this->user = null; } } $data['logout'] = $this->facebook->getlogouturl(array('next' => base_url().'login/logout')); $this->load->view('dashboard', $data); } users_model:
public function get_friends_on_drimmly($user_friends) { $return_array = array(); foreach ($user_friends $friend => $row) { $query = $this->db->select()->from('users')->where('id', $row['id'])->get(); if ($query->num_rows() != 0){ foreach ($query->result_array() $result => $row) { $return_array[] = array( 'name' => $row['full_name'], 'id' => $row['id'] ); } } } return $return_array(); } update: print_r($user_friends):
array ( [data] => array ( [0] => array ( [name] => daniella caspers [id] => 6710741 ) [1] => array ( [name] => alex dos santos [id] => 10029005 )....
with $user_friends data need adjust foreach to:
foreach ($user_friends['data'] $row) {
Comments
Post a Comment