0

I'm am creating a event listing website like eventbrite.com. There are organizers who can create events and users who can register for events.

Users need to login to the system via Facebook. In this case I get to store their facebook_id.

My question is, how can I get a particular user's friend list (friends who are attending the event) and display below the event?

Actually I have an idea for this:

Solution I
When a logged in user attending an event, I can save his facebook_id with the event id.

Event attenders table
facebook_id | ---- Event _id
42343453424 | ---- 08
34534534544 | ---- 08
23424243224 | ---- 10

When another user logs in, I can get his friends facebook_ids and try to match with the Event attenders table.

Example:
user_friend_list = [ 42343453424 , 23424243224 , 4345345345 , 245345433 ,...etc ]

I have to get the 1st user form the user_friend_list array (42343453424) and search in the Event attenders table, and the second user (23424243224) , and the third user so on.

This method needs to run lots of loops and queries. This will cause a huge delay in the site.

Can anyone please suggest me a better solution of doing this?

Thanks in advance!

-PS

  1. In eventbrite.com and eventful.com and there's a Facebook app that do this work. how to create such a Facebook book app to do this work.

  2. If I have multiple events on my homepage and I want to display the attenders list below each and every event once a user logs in. Is this possible to do smoothly?

Kara
  • 6,115
  • 16
  • 50
  • 57

1 Answers1

0

Instead of running all those individual database hits, why don't you bring back all attendees for an event in 1 query and store them in an array. Then get all a users friends and store them in another array. Finally loop through the list of attendees and use the in_array method to check if the current attendee is in the friend array. Then you can store these in a third array that is all the matching friends

e.g

 $matching = array();
 $attending = array(); // This is populated from your database
 $friends = array(); // This would be populated from their facebook friendlist

 $foreach($attending as $attendee){
       if(in_array($attendee, $friends)){
            // This attendee is present in their friends list so add them to matching
            $matching[] = $attendee;
       }
 }

 //Loop through matching to show all the friends who are attending.
TommyBs
  • 9,354
  • 4
  • 34
  • 65