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 8853451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:39:22+00:00 2026-06-14T13:39:22+00:00

I am building a small quiz/test engine with AJAX, PHP, and MySQL. All of

  • 0

I am building a small quiz/test engine with AJAX, PHP, and MySQL. All of the data (questions, answers, etc.) is stored in a database.

The issue that I am having is that I can’t find out how to filter out the questions that have been answered by the user that is logged in, therefore resulting in questions being repeated and a never ending quiz/test.

When you click the "next question" button, an AJAX request is sent to submit_answer.php which submits the answer (adds row to user_answers table) and it also sends a request to get_question.php which then returns JSON of the question information (question, answers, etc.) but I can’t seem to get it to not select questions that have been answered (questions in the user_answers table). Here is what I’ve got right now:

$question = mysql_query("SELECT *, q.id qid, q.question question_text 
                         FROM questions q, user_answers ua
                         WHERE q.id != ua.question_id 
                           AND ua.test_id = $test 
                           AND ua.user_id = $_SESSION[userid] 
                         ORDER BY rand() 
                         LIMIT 1");

$q = mysql_fetch_assoc($question);

This query is supposed to select the questions that have the test_id of the current test, has the user_id as the current user, and not in the user_answers table. But apparently, I’m just not doing it right.

You can see the entire get_question.php file here: http://pastebin.com/Td6mqp49

Edit:

Here are my table structures as requested by @MadaraUchiha:

questions

enter image description here

user_answers

enter image description here

  • 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-06-14T13:39:23+00:00Added an answer on June 14, 2026 at 1:39 pm

    You need a left outer join between the questions to the user_answers tables.

    The final query looks like:

    SELECT *, q.id qid, q.question question_text 
    FROM questions q left outer join
         user_answers ua
         on q.id = ua.question_id and
            ua.test_id = $test and
            ua.user_id = $_SESSION[userid] 
    WHERE ua.user_id is null
    ORDER BY rand() 
    LIMIT 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a small online app (PHP/MySQL) where users can sign-up to become
I am building a small quiz app and the choices are all list items
I´m building a small application with Jquery and PHP. Jquery (index.html) adds Form Fields
I'm building a small web search engine for searching about 1 million web pages
Background: I'm building a small application that will be run daily, pulling data from
First, I only have experience building small-medium sized websites with php so forgive me
i'm currently building a small music quiz running node.js 0.4.12 and the express framework
I'm building a small GUI-Test automation tool in C# for a application. One of
im building a small static qt library using VS2010, unfortunately, mysql got this error:
I am building a small website for fun/learning using a fairly standard Web/Service/Data Access

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.