Take the 2-minute tour ×

I have fetched friend list from facebook using below code:

$session = $facebook->getSession();

if ($session) {
    $uid = $facebook->getUser();

foreach ($friends as $key=>$value) {
    echo count($value) . ' Friends';
    echo '<hr />';
    echo '<ul id="friends">';
    foreach ($value as $fkey=>$fvalue) {
        echo '<li><img src="https://graph.facebook.com/' . $fvalue->id . '/picture" title="' . $fvalue->name . '"/></li>';
    echo '</ul>';

I have one query that I have fetched friend list from facebook using this API, but I have one input box where I have type john then this friend list should contain list of friends whose name is 'jhon'. How can I implement this functionality in existing code?


share|improve this question
add comment

3 Answers

What I do is store the friends names and user_ids in a table and update the table on fresh logins. So from there we can make an autocomplete endpoint that we hit through ajax.

SELECT * FROM `user_contacts`
WHERE `name` LIKE "%{$name}%" AND `user_id` = "{$user_id}"

We take the results of this query and json_encode it where we can pass this data straight into jquery ui autocomplete.


Seems to work well, however user_contacts table can fill up relativly quickly depending on how many Facebook users you have. I'm not 100% on Facebooks T&C's for storing this data so its worth looking into.

share|improve this answer
add comment

Get the function in_array, you can pass the array and the String you search for.

share|improve this answer
add comment

Here's a project that does something like what I think you're after: http://www.devthought.com/2008/01/12/textboxlist-meets-autocompletion/

This available in both Mootools and jQuery versions if I remember correctly.

share|improve this answer
add comment

Your Answer


