Saturday, 15 February 2014

php - Database query for timeline of a social networking site -



php - Database query for timeline of a social networking site -

i building social networking site , notice board scheme college.

i want show 10 15 recent posts friends of loggedinuser in home page.

if select rows of timeline table in database, consume more memory , fetch posts not of friends of loggedinuser.

so should best possible way so?

help me.

the table "friends" stores userid, friendid , status. table "timeline" stores posts of users postid , userid

i'm using apache, php , mysql.

thanks...

you'll want sql joins pretty before go build social network. i'm not gonna lie. basic question should able reply on own (without stack overflow) if you're planning on building social network of kind.

that said, here 2 queries work. , might seek experimenting both , reading on difference between two, performance implications of using 1 vs other. should mention, these give postids need, you'll need bring together posts table (presumably) actual post content. leave step you.

also, in terms of getting 10-15 recent posts, need inquire question... can reply question tables you've listed?

hint: can't. question: why not?

query alternative 1 (gets post ids belonging friends of friends.userid = ???):

select b.postid, b.userid friends inner bring together timeline b on a.friendid = b.userid a.userid = ???

query alternative 2 (gets post ids belonging friends of friends.userid = ???):

select b.postid, b.userid timeline b exists (select * friends friends.userid = ??? , b.userid = friends.friendid)

now, question you: both queries above homecoming same result? 1 preferable other? if so, preferable or depend on circumstance? can give me example?

php mysql

No comments:

Post a Comment