timmah1 Posted October 1, 2008 Share Posted October 1, 2008 I'm doing a contest, the contest consists of 50 yes or no questions. The questions are pulled from a database. What I cannot figure out, is how to post the information back to the database. When the questions are pulled from the database, each on has radio buttons for yes or no I cannot name the radio the radio buttons "yes" or "no", because then it will only work for one question I am doing this <input name="<? echo "q_$dailyrow[id]"; ?>" type="radio" value="1"> for the radio buttons, but how can I input into the database the question ID plus yes or no for each question? Any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/ Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 Can anybody help me out here? Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654677 Share on other sites More sharing options...
Maq Posted October 1, 2008 Share Posted October 1, 2008 Can't you use the value? Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654679 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 The value for the radio buttons is either going to be 1 for yes, or 0 for no. The name of the radio buttons cannot be the same because you will only be able to select one question. So each radio button pair have to have a different name, so I'm using the question ID as the radio button name Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654681 Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 Use an array? Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654688 Share on other sites More sharing options...
Maq Posted October 1, 2008 Share Posted October 1, 2008 Use arrays. One holds the name, the second holds the value of that question's answer (yes/no). Here's a simple example that you could use but need to implement an array: home and learn What I cannot figure out, is how to post the information back to the database. What's all the information that you need to store? User/Question/Answer? Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654689 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 yes. I need to store questionID name date answer Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654691 Share on other sites More sharing options...
Maq Posted October 1, 2008 Share Posted October 1, 2008 yes. I need to store questionID name date answer All this information can easily be extracted. Try using arrays. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654692 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 I understand that. But how do I get the info that was submitted for the database? My radio buttons are like so <input name="<? echo "q_$dailyrow[id]"; ?>" type="radio" value="1">yes <input name="<? echo "q_$dailyrow[id]"; ?>" type="radio" value="0">no Then the process part is where I get stuck for($counter=0;$counter < count($name);$counter++ ){ $guess_string .= $_POST['q_'.$name][$counter]; echo $guess_string; } I need to be able to echo out the question id along with 1 or 0 And I'm not sure how to do it Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654706 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 I've been trying different things, and nothing was being echoed out. I finally got the value to echo, but not the name of the button. Here is what my radio button looks like <input name="<?=$dailyrow['id']; ?>" type="radio" value="1"> And here is the code that process's it foreach ( $_POST as $postitem ) { echo '$name - <input type="text" name="postitem[]" value="' . $postitem .'"><br>'; } Can anybody tell me how I can actually echo out the name of the button too? Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654761 Share on other sites More sharing options...
revraz Posted October 1, 2008 Share Posted October 1, 2008 The table should contain the User ID, the Question ID and the answer. Since it's a Yes/No, you only need to store 0 or 1 uID | qID | Ans 1 1 0 1 2 1 etc I think you are over thinking it. You don't need a seperate name for each button, just a different array slot. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654762 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 Very true But what I'm trying to do, is give them a page that they would verify their answers before actually submitting them. That's why I'm trying to echo the questionID with the answer, then the questionID and grab the appropriate question and display it for them, if they are satisfied, then they click on submit, if they want to change an answer, then they would click change answer. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654773 Share on other sites More sharing options...
Brian W Posted October 1, 2008 Share Posted October 1, 2008 yes. I need to store questionID name date answer So, are u using some kind of statement that is looping your format each time with a different question, right? how about something like- <?php //your for, while, or whatever you use $i = $questionID; echo $question.': <input name="'.$i.'" type="radio" value="1" /><input name="'.$i.'" type="radio" value="0" />'; //close your statment and whatever. ?> Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654781 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 I'm using this <?php $dailysql = "SELECT * FROM pool ORDER BY id LIMIT 5"; $dailyres = mysql_query($dailysql); while($dailyrow = mysql_fetch_assoc($dailyres)) { ?> <?=$dailyrow['question']; ?> - <input name="<?=$dailyrow['id']; ?>" type="radio" value="1"> <?=$dailyrow['question']; ?> - <input name="<?=$dailyrow['id']; ?>" type="radio" value="0"> <?php } ?> This grabs all the questions. That isn't the problem. The problem is, when they click on submit, how would I have the page echo the question along with the answer? I can echo the answer with no problem, but since the input name is different with every question, I cannot figure out how to echo <input name="<?=$dailyrow['id']; ?>"> If someone could just show me the proper way to echo out the name of the input name, I would be greatly appreciative. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654786 Share on other sites More sharing options...
Brian W Posted October 1, 2008 Share Posted October 1, 2008 Sorry, my last comment wasn't of any help, you are already past that. I have an idea, again, may not be helpful. Add an incrementing value that loops with the question. The only use for it is to count how many questions. Then, at the end, have a hidden field that has that value in it so that you can pass it to the next page. then You could use that number in your statement to tell it how many times to loop. but again, I'm not sure if that is even helpful to you. If you are having a problem sending the question ID along, have a hidden field for each question that contains the question ID in the value. <input name="question<?php echo $i++; ?>" type="hidden" value="<?php echo $dailyrow['id']; ?>" /> btw, how are you resubmitting the values once you have them on the page for review? just interested. Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654793 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 I haven't gotten that far for re-submitting the form. But, if I get that far, I'll most likely hold the variables in hidden fields Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654801 Share on other sites More sharing options...
timmah1 Posted October 1, 2008 Author Share Posted October 1, 2008 I figured it out with list Form element <input name="q_[<?=$dailyrow['id']; ?>]" type="radio" value="1"> <input name="q_[<?=$dailyrow['id']; ?>]" type="radio" value="0"> and the process part $name = $_POST; while (list ($name,$val) = @each ($stock_)) { echo "$name, $val<br>"; } Thanks for everyone's help Quote Link to comment https://forums.phpfreaks.com/topic/126603-solved-radio-buttons-for-contest-help/#findComment-654807 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.