Hi,
I am totally new to php. can someone help me about how to use while loop with radio button and insert the values to table when submitted.
Thanks
How to use while loop with radio button
Moderator: General Moderators
Re: How to use while loop with radio button
A radio button will normally only occur once in $_POST. What are you 'looping' through? Perhaps a little more information?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: How to use while loop with radio button
@skmdas: if you're looping data retrieved from a database and which to create checkboxes that are POSTED as arrays then append the checkbox name with "[]".
Obviously when you validate the POSTED checkbox values you'll need to setup an additional loop, most suitable (i would imagine) is a for loop.
Obviously when you validate the POSTED checkbox values you'll need to setup an additional loop, most suitable (i would imagine) is a for loop.
Re: How to use while loop with radio button
Hi,
The one which i am working is a questionnaire. It has 15 to 20 questions and 4 choices for each question. the four choices is radio button ffrom that for each question one choice has to be selected. All the questions will be dispalyed in the same screen. once all the questions are answered you press the submit key and the question number and the answer is inserted into a table and based on that the score will be displayed.
Hope this helps you
Thanks
sree
The one which i am working is a questionnaire. It has 15 to 20 questions and 4 choices for each question. the four choices is radio button ffrom that for each question one choice has to be selected. All the questions will be dispalyed in the same screen. once all the questions are answered you press the submit key and the question number and the answer is inserted into a table and based on that the score will be displayed.
Hope this helps you
Thanks
sree
Re: How to use while loop with radio button
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I think i can help, below is just an example that should be in the body of the page:
----------------------
---------------------------------
Insert below into top of your page
--------------------------------
---------------------------------------
To print the results just echo the result you want, example below:
--------------------------------------
---------------------------------------
Hope thats want you were looking for. hope there isn't any mistakes
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
I think i can help, below is just an example that should be in the body of the page:
----------------------
Code: Select all
<form name="form1" method="post" action="page_name.php">
<input type="radio" name="question1" value="1">
<input type="radio" name="question1" value="2">
<input type="radio" name="question1" value="3">
<input type="radio" name="question1" value="4">
<input type="radio" name="question2" value="1">
<input type="radio" name="question2" value="2">
<input type="radio" name="question2" value="3">
<input type="radio" name="question2" value="4">
<!-- add more questions -->
<input type="submit" name="finish" value="Finish">
</form>Insert below into top of your page
--------------------------------
Code: Select all
<?php
if($_REQUEST['finish'])
{
$results = array();
#20 relates to number of questions
for($i=1;$i<=20;$i++)
{
$variable = "question".$i;
$results[$i] = $_REQUEST[$variable];
}
}
?>To print the results just echo the result you want, example below:
--------------------------------------
Code: Select all
Question 1: <?php echo $results[1];?><br>
Question 2: <?php echo $results[2];?><br>Hope thats want you were looking for. hope there isn't any mistakes
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Re: How to use while loop with radio button
why not pass the checkboxes as array directly from form using "[]"?