November 5th, 2012, 11:37 AM
I have 'questions' that get answered by 'customers'..
Now when a new question is made ALL CUSTOMERS should have the answer 0 set in the 'answers' table
So after the INSERT statement for the question i need to loop all the customers and give them 0..
Is there an easy way to do this?
Thanks! I'm really confused by this one
November 6th, 2012, 05:16 AM
Unless you provide more information about tables and example data the only answer you're likely to get is: UPDATE answers SET answer=0 WHERE something=value;
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
December 2nd, 2012, 06:42 AM
since the original post is kind of vague, 3 possible scenarios here:
1. there's one table for customers which has a column for each question.
-- In this case you want to insert a new column for the new question with the default value set to 0. This would require an ALTER query.
2. there's one table for questions. with a different column for each customer.
-- In this case you want to insert a new row for the new question with the default value set to 0. This would require an INSERT query, with the value for each customer column set to 0.
Neither of these seem likely.
3. There a table for customers, a table for questions, and a 3rd table for customer answers. the third table has a one to one mapping as in
| key | customer_id | question_id | answer |
-- Since this is a new question (let's say question 17), you want to INSERT a new row for the new question_id for each customer_id. I assume this is the scenario at hand. For that, you probably want something like this: