Facebook好友循环不起作用

The following code gets the Facebook friends of the logged in user, and checks if any of his friends exist in a database table gamers using the id of the Facebook friends.

 $friends = $facebook->api('/me/friends');

        foreach ($friends["data"] as $value) {

            $friendid=$this->upload_model->get_user($value["id"]);

              if (($friendid)) {

                $my_friends=$this->upload_model->get_user($value["id"]);
                $data['top_friends']=$my_friends;



            }


        }

This code is in my controller of my codeigniter application, where $this-upload_model->get_user() is a function in my model that gets all the information on a gamer.

The model:

public function get_user($id)
    {
        $this->db->where('id', $id);
        $user=$this->db->get('gamers');
        $data = $user->result_array();
        return $data;
    }

In the view:

<?php foreach ($top_friends as $friend) : ?>

<p><?php echo $friend['name']; ?></p>


<?php endforeach; ?>  

What I want to achieve is to search if any of the Facebook friends of the logged in user are also registered and are stored in the database table gamers. All of the friends who exist in the database would have their info printed in the view.

Currently with this code, the view only prints one entry. The one entry printed is a Facebook friend, but it should list all, of which in this case there are 2 friends stored in the database. But this code only returns one.

How do I fix this?

You have to pass as array

$temp = array();
 foreach ($friends["data"] as $value) {

            $friendid=$this->upload_model->get_user($value["id"]);

              if (($friendid)) {

                $my_friends=$this->upload_model->get_user($value["id"]);
                $temp[]=$my_friends[0];//as per your comment



            }
$data['top_friends'] = $temp;