I'm having some difficulty with a SELECT query that should be rather easy. Here's the simplified background:
I have two tables in my database. One table, named TABLE1, contains three fields: [QuestionID], [Question], [Answer]. The second table, named TABLE2, contains two fields: [UserID] and [QuestionID].
Basically, the functionality of the page is when a user answers a question correctly, the username and question ID will inserted into TABLE2. TABLE2 will be used to omit answered questions from the page so that the user will only be able to answer questions that have not been answered.
So, the SELECT query should work by 'Displaying all questions in TABLE1 that are NOT IN TABLE2'. This sounds very easy, but I can't figure it out.
Here's my queries:
$answered = mysql_query("SELECT QuestionID FROM TABLE2 WHERE Username='TESTING'");
while ($answered1 = mysql_fetch_array($answered))
{
$QuestionsToDisplay = mysql_query("SELECT * FROM TABLE1 WHERE 'QuestionID' NOT IN ('$answered1')");
}
}
I also tried:
$QuestionsToDisplay = mysql_query("SELECT * FROM TABLE1 WHERE 'QuestionID' !='$answered1'");
Both instances display one result when it should be displaying 4.
I put the first query in a 'while' statement because it returned the right data (I have two entries in TABLE2 for testing purposes, and that's what the echo statement displays).
So any idea what I'm doing wrong?
Thanks!!