I'm trying to create a radio button in a loop, but I want to assign a unique id so it becomes a group where only one radio can be selected. Is this possible? My loop duplicates the same radio and I can select every button. I only want to select one.
<?php
$i = 0;
$i = $i++;
while($i>=0)
{
echo "<input type='radio' name='test[$i++]' value='test[$i++]'>test[$i++] ";
echo "<BR>";
$i++;
}
?>
UPDATE THIS WORKS!!!
<?php
$i = 0;
while($i++ < 5)
{
echo "<input type='radio' name='test' value='test[$i]'>test[$i] ";
}
?>
Learn basic PHP syntax. "$i++"
is a string that contains a variable ($i
), and two +
characters. it's NOT going to increment your $i
variable.
You're literally generating the following html:
<input type='radio' name='test[1++]' value='test[1++]'>test[1++]
<input type='radio' name='test[1++]' value='test[1++]'>test[1++]
<input type='radio' name='test[1++]' value='test[1++]'>test[1++]
As well, as written, your while()
is going to be an infinite loop, since $i will ALWAYS be greater than 0.
Try this instead:
while($i++ < $limit) {
echo "<input type='radio' name='test[$i]' value='test[$i]'>test[$i] ";
}
you can use of bottom code.please preuse input tag(value).
`<?php for($i=1;$i<10;$i++) { `?>`
<input name="RadioBox" type="radio" value="<?php print($i); ?>" />
<?php } ?>