Page 1 of 1

dynamic readio button loop - assigning name and passing

Posted: Wed Sep 14, 2005 7:31 am
by btm
Hi!
So I'm creating an online form that pulls information from a database and inserts part of it into a series of radio buttons. The issue is that in order for the radio buttons to function independent of each other, each one needs a unique name. I've suceeded in creating an incrementing variable that I attach to the beginning of each radio button as it goes through the loop, but I can't figure out how to get the data to the next page or into the database...
Code:

Code: Select all

while($row = mysql_fetch_assoc($result))
	{   //this loops out the data into multiple columns	 

		print("<td align='left' style='padding: 3px;'>"); 
		print("<textarea name='description[]' rows='2' cols='20'>$row[description]</textarea><br /> \n");
		
		if(trim($row[success_flag]) == "success")
		{
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'success" CHECKED/> Success <br>');
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'failure"/> Failure <br>');
			print("</td> \n\n");						
			$i++;
		}
		else if(trim($row[success_flag]) == "failure")
		{
			
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'success"/> Success <br>');
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'failure" CHECKED/> Failure <br>');			
			print("</td> \n\n");
						
			$i++;

		}
		else
		{
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'success"/> Success <br>');
			echo ('<input type="radio" name="success_fail[]'.$i.'" value="'.$i.'failure"/> Failure <br>');
			print("</td> \n\n");
			
			$i++;
		}

	}
This comes out in the page source as:

Code: Select all

<input type="radio" name="success_fail[]1" value="1success" CHECKED/> Success <br>
<input type="radio" name="success_fail[]1" value="1failure"/> Failure <br></td> 

...code...

<input type="radio" name="success_fail[]2" value="2success" CHECKED/> Success <br>
<input type="radio" name="success_fail[]2" value="2failure"/> Failure <br></td> 


<input type="radio" name="success_fail[]3" value="3success"/> Success <br>
<input type="radio" name="success_fail[]3" value="3failure" CHECKED/> Failure <br></td>
I'm basically trying to figure out what the variable that gets passed looks like and how to play with it (at least print each passed value out to begin with).

Anyone have any ideas? Thanks :P

Posted: Wed Sep 14, 2005 9:31 am
by raghavan20
Run this example and you will know wot you should do.

Code: Select all

<form method='get'>
<?php for($i=0; $i < 3; $i++){ ?>
	<?php  echo "Radion button set:$i"; ?><br />
	<input type="radio" name="success_fail[<?php echo $i; ?>][]" value="success" CHECKED/> Success <br> 
	<input type="radio" name="success_fail[<?php echo $i; ?>][]" value="failure"/> Failure <br>
<?php }?>
<input type = 'button' value = 'submit' onclick = 'form.submit();' />
</form>


<pre>
<?
if (isset($_GET) && is_array($_GET)){
	print_r($_GET);
}
?>
</pre>

Thanks

Posted: Wed Sep 14, 2005 12:28 pm
by btm
Perfect!

Thanks.