Schema to build a user updates dashboard activities ala facebook - php

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.

Related

General questions about database

I would like to create e-learning platform. So users will have a lot of things to choose (mostly available to view only for them) like:
add note
add movies to favorite
rate the instructor
And few options that auto save for each user like:
unanswered questions
wrong answer questions
movies in progress (user saw only 2 min from 5)
So what database or method I schould use for store that kind of data?
I do not want to use cookies because it needs to be save on user account and not on browser. User need to have that all on every browser or mobile device.
I wondering about json but...if I do so each user I'd will be available to view...so schould I use MySQL?
I would recommend that you build your own data logger, what i mean by this is build yourself a place to store every users data like an eManager if you would like.
Once this has been built you can then assign the eLearning courses using an ID to each of the users profile on your "eManager". Allowing you too keep track of each users progress etc.
The "eManager" could also save the users notes/wrong answers/unanswered questions, you could create surveys with a slider rating to rate the user. Honestly the limit is endless.
You can receive the data in two different ways:
(Personal) Either you can request that your users email you requesting a username and you generate a password and send it out to the user.
(Commercial) You build your eManager to recieve the data from the website which isnt too difficult to do.
It will be a long process and to answer your question in a different view practice SQL/PHP that would be your base make sure you can run more advanced query's and can confidently edit your DB etc.
Anymore questions just let me know, thanks.

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.

PHP newsfeed from people that you follow

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.

How can I deal with deleted photos in an activity stream

In our app, users can upload photographs. This upload event is registered as an activity and pushed into that users 'followers' activity streams.
The flow and tech used is as follows:
MYSQL backend for storage (url of uploaded image is stored in photos table along with some metadata)
Activity is generated and stored in activities table in MYSQL
GEARMAN job is created which sends the activity ID to REDIS where this activity ID is fanned-out to all the users followers in order to populate their activity streams.
We retrieve a stream by getting the array of activity ID's from REDIS and then performing a simple IN query in MYSQL.
In a users activity stream a small cropped version of the image is visible.
Now this all works fabulously and along with several caching layers has helped keep the system very stable and scaleable.
However, what is considered the best way to deal with a user who chooses to delete one or more of their photos. Currently, when they delete a photo all their followers will get a broken image link in their activity streams.
Therefore we need to choose between two methods of dealing with this.
Store the activity id in the photo table, and delete the activity relating to the photo when a user deletes that photo. This would work nicely but would see a user have activities removed from their streams occasionally.
Flag the image as deleted in the photos table and when generating the stream display a "this image has been deleted by the user" message.
Which would be considered the best approach to take and why? Alternatively are there any other better ways of dealing with this that people would recommend?
Many thanks.
IMO it would be best to make this as transparent as possible. Tell the other users that the image was deleted and offer an option to drop the entry from the activity stream. That way the user stays in control and has no "magick" happening in the background. Maybe for very old entries (what ever this means in current times) you can remove the item automatically. But I would always prefer to get the respective information.

Upload image to member area, subject to admin approval

I'm trying to create a members site using php where they can upload images (dynamically create thumbnails) and comments for all members to see. I want all uploads to be published only after admin approval.
I can do quite a lot of this (registration, login, and even basic upload)but would be grateful if someone can provide a link to any lessons or videos of how to put it all together. I really would like to learn how to do it rather than configure someone's script.
I've checked YouTube but cannot find exactly what I'm looking for.
Thanks
In order to do an approval system, I think the most simple way to do it is to have a field in a DB, for each comment, image, etc, named "approved", which can take a 0,1 or 2 as value.s
If it's 0, it means it needs approval. 1 means it's approved. 2 means it is disapproved.
Note that 2 is not really necessary. It's just to distinguish new entries from old entries that weren't approved.
Then, on the backend, you can only give access to the approval system to the admin. You can use the same approach to define admins, users, moderators, etc...

Categories