How to use INSERT with WHERE
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?
Your can try something like this:
INSERT INTO t1 (id, title) SELECT id,title FROM t2 WHERE t2.id>10
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".
精彩评论