Hi, I'm developing a social service and I have a question about how user info should be loaded.
Let's assume a user clicks on an image, and I show him all of the comments. I need to know which comments the user liked. I was thinking that instead of loading all of the comment id's of all the comments the user liked over and over, I can just load them all when he/she logs in. However, I'm not sure if that's the right approach or how exactly to store them (I'm guessing storing arrays on $_SESSION isn't a really good idea. What's the best, most conventional, most space & time efficient to load user info such as that?

Recommended Answers

All 3 Replies

Hi,

I'm a little bit confused by what you're asking. When you say "loaded" do you mean displayed??

So, in other words, here on DaniWeb, you can use the vote up / vote down arrows next to each post. If you've voted on a post in the past, then the arrow that you picked is forever highlighted.

What we do is have a posts table and then a separate votes table. The posts table has columns for who posted the comment, the actual comment, and the unique post id of the comment.

The votes table has a column for who voted and the unique post id that was voted on.

What you would then do when querying the posts table of the database for comments on a particular photo is, if the end-user is logged in, JOIN the votes table by SELECT'ing on rows where the voter is the logged in user and the post id is one of the post ids already being pulled for the specific photo. This also gives you the ability to query the database for all of the posts voted on by a particular member over time.

Of course, it would be silly to fetch ALL comment IDs every time a member logs in because, over time, there could be tens of thousands, all loaded for no reason!

@Dani Thanks! I have the same exact database setup (one table for comments and another for votes), but I didn't think about JOIN & SELECT.
I really appreciate that, you solved me a lot of headaches :).

Glad that helped you. I'm going to go ahead and mark this thread as solved. In the future, please mark threads you start as Solved once you've received help. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.