0

I need to INSERT data into my MySQL database depending on whether a field in another table in the database is TRUE or FALSE (bool). The PHP code I have so far goes something like this:

//Insert data into database
mysql_query("INSERT INTO answers (name, answer, aQID, date)
    VALUES ('$name', '$answer', '$curdate')");

I am wondering where I could put the WHERE clause. It needs to be something like this

WHERE approvedQuestions status = TRUE

I am hoping I'm explaining myself clearly. Since I am not displaying data I do not believe I need to be using the UNION but I could be wrong.

EDIT: Each question has a unique ID associated with it. The unqiue ID is also present in the answer table for association purposes. Only thing is all the relationships are being done PHP wise and not MySQL wise. What would be the best way to assign the unique questionID to the answer table?

DrakeNET
  • 183
  • 1
  • 2
  • 8

2 Answers2

2

Your can try something like this:

INSERT INTO t1 (id, title) SELECT id,title FROM t2 WHERE t2.id>10
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
publikz.com
  • 931
  • 1
  • 12
  • 22
1

You can use 0 for FALSE and 1 for TRUE values. It's mostly simple.

ps Instead of this you can change type of row in phpmyadmin for "BOOL".

NiLL
  • 13,645
  • 14
  • 46
  • 59
  • I forgot to mention, each question has a unique ID, so what would be the proper way to insert the current ID into the table? – DrakeNET Jul 03 '11 at 19:26
  • As I understand, you must use "UPDATE approvedQuestions SET status=1 WHERE id=id; – NiLL Jul 03 '11 at 19:37