Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4039140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:34:02+00:00 2026-05-20T12:34:02+00:00

I’m currently working on a medium-sized web project, and I’ve ran into a problem.

  • 0

I’m currently working on a medium-sized web project, and I’ve ran into a problem.

What I want to do is display a question, together with an image. I have a (global) list of questions, and a (global) list of images, all questions should be asked for all images.

As far as the user can see the question and image should be chosen at random. However the statistics from the answers (question/image-pair) will be used for research purposes. This means that all the question/image-pair must be chosen such that the answers will be distributed evenly across all question, and across all images.

A user should only be able to answer a specific question/image-pair one time.

I am using a mysql database and php. Currently, i have three database tables:

tbl_images (image_id)

tbl_questions (question_id)

tbl_answers (answer_id, image_id, question_id, user_id)

The other columns are not related to this specific problem.

Solution 1:
Track how many times each image/question has been used (add a column in each table). Always choose the image and question that has been asked the least.
Problem:
What I’m actually interested in is distribution among questions for an image and vice versa, not that each question is even globally.

Solution 2:
Add another table, containing all question/image-pairs along with how many times it has been asked. Choose the lowest combination (first row if count column is sorted by ascending order).
Problem:
Does not enforce that the user can only answer a question once. Also does not give the appearance that the choice is random to the user.

Solution 3:
Same as #2, but store question/image/user_id in table.
Problem:
Performance issues (?), a lot of space wasted for each user. There will probably be semi-large amounts of data (thousands of questions/images and atleast hundreds of users).

Solution 4:
Choose a question and image at true random from all available. With a large enough amount of answers they will be distributed evenly.
Problem:
If i add a new question or image they will not get more answers than the others and therefore never catch up. I want an even amount of statistics for all question/image-pairs.

Solution 5:
Weighted random. Choose a number of question/image pairs (say about 10-100) at true random and pick the best (as in, lowest global count) of these that the user has not answered.
Problem:
Does not guarantee that a recently added question or image gets a lot of answers quickly.

Solution #5 is probably the best once I’ve come up with so far.
Your input is very much appreciated, thank you for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:34:02+00:00Added an answer on May 20, 2026 at 12:34 pm

    From what I understand of your problem, I would go with #1. However, you do not need a new column. I would create an SQL View instead becuase it sounds like you’ll need to report on things like that anyway. A view is basically a cached select, but acts similar to a table. Thus you would create a view for keeping the total of each question answered for each image:

    DROP VIEW IF EXISTS "main"."view_image_question_count";
    CREATE VIEW "view_image_question_count" AS 
    SELECT a.image_id, a.question_id, SUM(b.question_id) as "total"
    FROM answer AS a
    INNER JOIN answer AS b ON a.question_id = b.question_id
    GROUP BY a.image_id, a.question_id;
    

    Then, you need a quick and easy way to get the next best image/question combo to ask:

    DROP VIEW IF EXISTS "main"."view_next_best_question";
    CREATE VIEW "view_next_best_question" AS 
    SELECT a.*, user_id
        FROM view_image_question_count a
        JOIN answer USING( image_id, question_id )
        JOIN question USING(question_id)
        JOIN image USING(image_id)
    ORDER BY total ASC;
    

    Now, if you need to report on your image to question performace, you can do so by:

    SELECT * FROM view_image_question_count
    

    If you need the next best image+question to ask for a user, you would call:

    SELECT * FROM view_next_best_question WHERE user_id != {USERID} LIMIT 1
    

    The != {USERID} part is to prevent getting a question the user has already answered. The LIMIT optimizes to only get one.

    Disclaimer: There is probably a lot that could be done to optimize this. I just wanted to post something for thought.

    Also, here is the database dump I used for testing. http://pastebin.com/yutyV2GU

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to parse a xhtml file and display in UITableView. what is the
I need to clean up various Word 'smart' characters in user input, including but
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.