I wrote an application, its not a social networking script by any means, but my script does have "user profiles" for it and I'm interested in a SQL/PHP design idea to go about activity streams as seen on Facebook for the users of my script.
Activities such as "Joey commented on X's wall." or "Joey, X, Foo like your photo" or "Foo changed his picture [picture here]"
I want it to be dynamic, not static entries, because if Joey changes his name to something else, I don't want it to show old data.
So, if you would please, help me out with a way to design this... I don't need any code just a push in the rig开发者_如何学JAVAht direction.
Thanks alot!
I'm not sure in the long term that your proposed schema will give you much flexibility:
DB schema is what I am looking for. I was thinking maybe something like.... activity_id activity_message activity_time Where message will be something like "{USERID:34} likes {USERID:23} post" and "{USERID:34} changed his picture {PHOTOID:2}"
The problem with this is you're then relying on regular expressions and other expensive (in time) methods of parsing this for display.
Perhaps (I've never had to practically design this sort of thing) if you have a separate table for "likes" which has user.id, post.id, timestamp, you can then for a particular post easily count the number of people who like it, for an activity stream you can filter by user and order by time. The stored user.id is the person who liked the post and you can then do a join on the post.id to get the user associated with that post.
For dealing with pictures and/or other interactions you could have a table containing, user.id, item.id, action, timestamp, where item.id is a picture/post/other id reference and the action is a numeric identifier corresponding to the action which you can then associate with a string.
By doing things this way you have other advantages in that if you wish to have multiple languages later or decide to change the term "likes" to "enjoys" you can do it easily where as if you stored a text string which would later be displayed you'd have more difficulty in replacing it.
精彩评论