Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Fetch Recent Activity as Newsfeed for Social App in MySQL PHP

    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 868
    Answer it

    I am working on a MySQL PHP social networking application and I want to Fetch Recent Activity as Newsfeed with respect to post activity timings.

     

    Here is my site database, i am writing only few columns which are required to show.

     

    • users : u_id,f_name,l_name,dp
    • posts : p_id,u_id(foreign key)    ,p_content,p_date,post_status
    • Friends : friend_id,sender_id,receiver_id,status(2 means you are friend,1 means pending request)
    • page_like : id, page_id,who_liked,time
    •  

    Here is the table structure for my database, what i need is if i am having friends and i have liked pages and now i want to show users their newsfeed just like facebook show with respect to posts time( i need newsfeed like of facebook have, so plz tell me query for this by considering my this database structure)

 1 Answer(s)

  • Hi,
    A per your requirement, I am writing a query.
    (SELECT u.u_id, f_name, l_name,dp,p.p_date as post_date,'post_activity' from users u,friends f,posts p where u.u_id=receiver_id and f.sender_id=login_user_id and f.receiver_id=p.u_id)
    UNION
    (SELECT u.u_id, f_name, l_name,dp,p.time as post_date,'page_like_activity' from users u,friends f,page_like p where u.u_id=receiver_id and f.sender_id=login_user_id and f.receiver_id=p.who_liked) order by post_date desc
      Output:
    u_id 	f_name 	l_name 	dp 	post_date Ascending 	post_activity 
    
    	
    4 	I 	J 		2017-05-24 02:03:00 	post_activity
    3 	E 	F 		2017-05-24 00:00:00 	page_like_activity
    3 	E 	F 		2017-05-24 00:00:00 	post_activity
    This query will get the recent activity for post and like_page of your friends.
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: