Click to See Complete Forum and Search --> : auto display correct number of radio buttons


ketanco
10-04-2008, 05:07 PM
Hi,
I have a poll table that contains the questions and the code below displays the questions with radio buttons. I get $q values from database. Now, I dont have 5 questions all the time. Sometimes I have less. Lets say I have three questions, the code below displays 4th and 5th buttons regardless. How can I make it automatically display the appropriate number of options? (i.e. if I have 3 questions, immediately after displaying the third option, it needs to display the submit button)
I tried if statement, but my php knowledge is not enough how to make it work.

<form method="post" action="updateanswers.php">

<?php echo $title; ?>
</br>
<input type="radio" name="answer" value="answer1">
<?php echo $q1; ?>
</br>
<input type="radio" name="answer" value="answer2">
<?php echo $q2; ?>
</br>
<input type="radio" name="answer" value="answer3">
<?php echo $q3; ?>
</br>
<input type="radio" name="answer" value="answer4">
<?php echo $q4; ?>
</br>
<input type="radio" name="answer" value="answer5">
<?php echo $q5; ?>
</br>

<input type="submit" value="submit my answer"/>
</form>

skywalker2208
10-04-2008, 06:02 PM
Find out how many answers there are and then loop through them with a for loop.

ketanco
10-04-2008, 06:04 PM
what do you mean exactly by saying "loop through them" please?

skywalker2208
10-04-2008, 11:35 PM
because this part of your code is similar.

<input type="radio" name="answer" value="answer1">
<?php echo $q1; ?>
</br>


All you need to do is loop through each answer, but just changing the value each time it loops through.

ketanco
10-05-2008, 07:26 AM
thanks