PHP newsfeed from people that you follow - php

So I'm building a music social network in PHP and now I'm stuck at the newsfeed. It should work just as any other newsfeed (Twitter, Facebook ...) and at first point it should be as simple as possible.
I don't have any problem with displaying all the posts from my MySQL database from newest to oldest, but I only want to show posts by users that I follow.
I don't need exact code, just a theoretical explanation how to do it.
I have two MySQL tables - users and posts. Do I need anything else?
Thank you!

Save the user id of the users. Build an API to retrieve the information. Save it into your database and retrieve the info via ajax every minute or so. Simple.

Keep track of which users follow who, then retrieve the posts of the users that the current logged in user is following.
You dont need new tables for this, add a new column in your users table that holds an array of id's of the users you re following. And in your posts table a column which holds the id of the user to who the post belong.

Related

How to get data like tinder of unique users each times

I am planning to build a dating site. but want some suggestion in getting display users data. In my project, there will be no swipe feature instead we use multiple buttons to send different req. to users.
My Motive for the project is to get the nearest active users first according to interests. All of the modules are done only showing the nearest users algorithm is on hold.
we have to calculate the user's distance from the logged-in user location based on latitude and longitude. Then see the active users who are most close to the logged-in user.
I have stored logged-in users' latitude and longitude in DB.
This is a web project built in laravel-8.
I have to fetch 1 user record at a time after getting the nearest active user.
Note: Main I have to get a solution to get the next user on each click. I have tried it with pagination but that is not a good practice. I need some suggestion to other method to get 1 next user data at a time.
You can checkout inRandomOrder().Seems like it can be handled in one query. Further you can create api to get new user each time.
Try this:
$randomUser = DB::table('users')->whereNotIn('id',$userIdArrayAlreadyShown)->inRandomOrder()->first();

How to build chat rooms attached for a single user profile?

I have a simple php user profile system that works like this: When user is registered he gets a specific url ?user. Therefore, other visitors can access his page.
What I want it to include chat application on users profile pages. But, every single user should have its own chat.
Which approach is the best, as I am a beginner in this? Should I put the messages from chat into the database or should I work with some log.txt files?
Any good tutorial for this would be helpful.
I found some tutorial for you: http://tutorialzine.com/2010/10/ajax-web-chat-php-mysql/
- looks like it could help you.
The only thing you need to adjust is to add room column in WEBCHAT_LINES table - that will be the unique name of the user, into which's chat room the chat line belongs. Then, when new chat line will be sent, you must save it to DB with apropriate room identificator. When you display the messages in chat, you must filter the results in each room to show only the lines for this particular room.
If you haven't use database before, there are plenty tutorials about mysql around the internet - it's not that difficult.
Good luck! And use Google when you'll have some doubts.

how to set comment as unread/read with multiple users

i have a development blog in my project.i want add facility of set comment as unread for user until he/she see the comment.
suppose admin post a comment so for all users in that project should get that comment as unread
can anyone help
should i use $_SESSION or i have to use database tables?
You should use Database. Create 3 tables at least: user, comment, userReadComment since user read comment is a multi-to-multi relationship.
This calls for a proper design of the project.
What do you mean by :
i want it in php code...can any one help....i m totally stuck
?
You have to use Database only. It is as simple as this, once you have the comment table where you refer its ID and along with that you do user ID... if it is present, its read else, it isn't!
Or
You can set an enum of read or unread.
Can you show what have you done so far?

Schema to build a user updates dashboard activities ala facebook

Assuming that I have a simple website where users can upload photos and they follow each other.
If I follow someone I can see all the updates the users I follow do. Period.
So the user dashboard will show the recent photo uploaded. Simple as that.
My question is:
I was wondering if is better to just query the photo table for where the photos have user-id of people I follow, or create an activity table where I can store the upload etc, or is this redundant?
Well, I suppose it depends how many different kinds of updates you want to show your users. If photos are the only thing you want to display, it's probably not worth making a separate table.
But if you have lots of different kinds of updates then it could be worth making an "updates" table to aggregate them so you only have to query one table to display the dashboard.

How to find out maximum number of likes and comments in facebook using Graph api

I want to retrieve the profile ids from my friends list those who comment and like most of the stuff I put on my wall.
So far I have retrieved a list of 30 friends who share the maximum mutual friends with me.
Now I need to sort these 30 again based on comments+likes.
I use php.
EDIT:
Any specific answers with Code sample is greatly appreciated
Hi First you need to query the Linktable using FQL. This will return you whole objects that you has posted. Then you just need to again query to Like table. It will return you user id's who likes that page. Then you can compare those user id's with your user id's. i hope it will work ;-)

Categories