#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    74
    Rep Power
    2

    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?
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    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!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    74
    Rep Power
    2
    Basically here is the approach I'm currently using:-

    table 'question'
    Field 'text'
    Field 'user_name'

    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?
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,066
    Rep Power
    1990
    You should only need one query, just do a join on the database tables.

    Without knowing much about your DB schema, eg:

    Code:
    SELECT
        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
    That uses a single query instead of doing separate queries for each question/topic.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    0
    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!

IMN logo majestic logo threadwatch logo seochat tools logo