xxreenaxx1 Posted March 8, 2011 Share Posted March 8, 2011 I am trying to insert what I have Printed on my page. I have two tables Question table layoyt: Que_ID Que_Choice1 Que_Choice2 Que_Chocie3 Que_Choice4 Answer table layout: Que_ID Ans_Choice1 Ans_Choice2 Ans_Choice3 Ans_Choice4 Use_ID With these two tables, the first table is used to output the choice that has been made by the user and I can echo these. User ID: 1 Question ID: 1, Choice: 1. value: 1 Question ID: 2, Choice: 2. value: 1 Question ID: 3, Choice: 3. value: 1 Question ID: 4, Choice: 4. value: 1 with these result I want to insert Question ID, choice that is selected as 1 to my answer table. But my PHP is for loop. This is how I am printing the result session_start(); $name= $_SESSION['username1']; echo "User ID: $name <br/>"; $gender = $_POST["choice"]; $que_ID = $_POST["Que_ID"]; foreach ($gender as $key => $array) { if($array) { $val=1; } ///echo "Question ID and the choice ID:$key. Value is:.$val <br />\n"; $well = array(floor($key), substr(strstr($key, '.'), 1)); //$well = array(floor($key), $key - floor($key)); echo "Question ID: $well[0], "; echo "Choice: $well[1]. value: $val<br/>"; } //}break; ?> How would I insert what I have echoed into my answer table. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/ Share on other sites More sharing options...
fenway Posted March 8, 2011 Share Posted March 8, 2011 That's just not a great DB design -- not normalized at all. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1184487 Share on other sites More sharing options...
xxreenaxx1 Posted March 8, 2011 Author Share Posted March 8, 2011 why not? I am not repeating anything, so yehh. May be I am being stupid, but is there any error in my table. If yes, what is it Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1184616 Share on other sites More sharing options...
fenway Posted March 8, 2011 Share Posted March 8, 2011 why not? I am not repeating anything, so yehh. May be I am being stupid, but is there any error in my table. If yes, what is it Que_Choice1 Que_Choice2 Que_Chocie3 Que_Choice4 That's repeated 4 times. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1184710 Share on other sites More sharing options...
xxreenaxx1 Posted March 9, 2011 Author Share Posted March 9, 2011 May be I didn’t explain it clearly. I have a question for this I have four choices. So I would need them row to insert different answer for these rows. And it’s a multiple choice. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1184926 Share on other sites More sharing options...
TOA Posted March 9, 2011 Share Posted March 9, 2011 May be I didn’t explain it clearly. I have a question for this I have four choices. So I would need them row to insert different answer for these rows. And it’s a multiple choice. So for each question, it will have 4 possible answers...if I'm understanding. And will these 4 choices be the same for every question? ex: 1. Ques 1 a. 1 b. 2 c. 3 d. 4 2. Ques 2 a. 1 b. 2 c. 3 d. 4 I have a db schema and code for you to base yours on, but would require you to change your db structure, to be normalized, like fenway said. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1185222 Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 May be I didn’t explain it clearly. I have a question for this I have four choices. So I would need them row to insert different answer for these rows. And it’s a multiple choice. Does your table have multiple columns for each question/answer? Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1185331 Share on other sites More sharing options...
xxreenaxx1 Posted March 10, 2011 Author Share Posted March 10, 2011 yes Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1185520 Share on other sites More sharing options...
fenway Posted March 10, 2011 Share Posted March 10, 2011 Then you _are_ repeating things. Quote Link to comment https://forums.phpfreaks.com/topic/229972-insert-into-trouble/#findComment-1185553 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.