November 6th, 2013, 11:33 AM
Forum design - help with user's profile picture
I am making a forum and facing this problem with showing user's profile picture.
In the database I have a table that stores question and user_id of the user who asked it.
Now if I want to display the user's profile pic along with the question, I have to search for the corresponding user in user's table and retrieve his/her profile pic. This is done each time when the page loads making it slow.
Other option is that I store the profile pic also in the table. But if the user changes his profile pic, the table will be outdated. I can update the table each time user changes his profile pic though. But is there some other solution to this problem?
November 6th, 2013, 05:51 PM
Both options involve getting the picture or the ID/URL from the database so I can't see any performance difference there. If performance is going to be an issue, get all of the details that you need for the user at the time when you're getting their names to display.
And whatever you do, don't store images in the database. It's a terrible idea for a huge number of reasons. If you're concerned about performance then it's one of the best ways to make your system even slower!
November 7th, 2013, 07:24 AM
Basically here is the approach I'm currently using:-
Now when I display the question I need to show user's profile pic too so I search the database for the same user_name and retrieve his profile pic. This is done for each question.
How do I make this better? I see that in this forum also profile pic is shown. How is that implemented here on devshed forums?
November 7th, 2013, 05:30 PM
You should only need one query, just do a join on the database tables.
Without knowing much about your DB schema, eg:
That uses a single query instead of doing separate queries for each question/topic.
q.text AS text,
u.name AS name,
u.profile_pic AS profile_pic
FROM questions AS q
LEFT JOIN users AS u
ON u.id = q.user_id