Jump to content

how have they done this


jonniejoejonson

Recommended Posts

Can someone tell me how they do this.

 

On facebook, if you do a search for a friend, on the results page will be a list of users that match that name. By each user there will be options of things you can do.

If you are already friends with that person, the options are different… therefore when facebook does a search it must also cross reference the search results with your friends table… or do you think that when you login they store all your friends in a session?… and then cross reference the search results with your session?

 

Another example pointing towards the session theory is that, when you start typing a friends name in a search box it predicts the name you are typing…. This would indicate to me that when you login, face book grabs all your friends names and Id’s and stores them in a session, rather than having to do more complex database queries?

 

Can anyone tell me how they think it is done. Kind regards J

Link to comment
https://forums.phpfreaks.com/topic/122148-how-have-they-done-this/
Share on other sites

They query is conditional but they probably aren't running MySQL but Oracle so they structure of querying is a lot different and as you expect tables are lot more dependent on each other.

 

 

You could select via a GROUP_CONCAT all you friend's id in the mysql query and then if a user's ID matches a value in the GROUP_CONCAT it shows the special buttons for your friends.

 

 

Its not difficult to do just a bunch of ways to do it depending on your DB strucutre

Okay thanks for your response,

That would be how i would compare friend id's in my search query, however if the friend id's are stored in a session then it would save on having to do an extra database query... plus it would explain the predictive text...

if you start typing in the search box (on every page) it predicts your friends names.

They aren't querying the database every time you type a letter,

so that must mean they either query and get all your friend Id's before each page loads, or they must just store this in a session?...

do you think this is correct tor am i just talking crazy?

at the max the session would habve to store 5000 id's (max nos of friends)... that would be okay right?

thanks for you help.

they use ajax to do that.

 

 

here is an example PHP MySQL

http://www.w3schools.com/php/php_ajax_suggest.asp

 

as for database set up you use 2 tables

 

Users & Friends

 

users table

UID

Firstname

blabla

blablabla

 

 

Friends

UID1

UID2

Status

 

 

UID1 is the person who has

asked the UID2 to accept and the default status would be pending...

untill the user accepts then they are friends otherwise if rejected delete the entry

 

bla bla bla hope it helps

 

not necessary sometimes they know who you are and they know what sort of actions you will take but they dont know which order right.

 

so they can also load all of ur friends and hide them using css that can make it faster.

you see because they have the money they also have much more powerful servers to deal with those.

 

look at the youtube search. it has to deal with much more querries and more diverse load of crap lol

they do use ajax its the only way u can get data that way unless you have hidden them with css lol

style="display: none;" 

then manipulate it using javascript lol

 

not saying i know it 100% but its the most likely way they have done it. click on that page that i gave you and you will see that it too is almost instant.

Thanks again for your continued response... and i agree that the example you showed is good, however it isn't searching a databse for the names, it searching a php array of names... which would make it quicker...

but surely if when a user logs in i store that users friends id and names in a session, I would be able to use just javascript to make the predictive text, becauase all the names would already be on the users machine.

thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.