I am trying to make a variable yes/no radio type.
My script is:
while ($row1 = mysql_fetch_assoc($vragen))
{
$type = $row1['type'];
if ($type == 'kort')
{
echo '
<tr>
<td width="60%">'
.$row1['vraag'].'
<input type="hidden" name="vragen'.$aantalBranches.'[]" value="'.$row1['vraag'].'"/>
</td>
<td>
<input type="text" name="antwoorden'.$aantalBranches.'[]"/>
</td>
</tr>';
}
elseif ($type == 'lang')
{
echo '
<tr>
<td width="60%">'
.$row1['vraag'].'
<input type="hidden" name="vragen'.$aantalBranches.'[]" value="'.$row1['vraag'].'"/>
</td>
<td><textarea name="antwoorden'.$aantalBranches.'[]" cols="30"rows="5"></textarea><td/>
</tr>';
}
elseif ($type == 'ja,nee')
{
echo'
<tr>
<td width="60%">'
.$row1['vraag'].'
</td>
<td>
<input type="radio" name="optie'.$c.'" value="yes">Yes
<input type="radio" name="optie'.$c.'" value="no">No
</td>';
if ('optie'.$c.'' == 'yes')
{
echo'
<td><input type="hidden" name="vragen'.$aantalBranches.'[]" value="'.$row1['vraag'].'"/></td>
<td><input type="text" name="antwoorden'.$aantalBranches.'[]" value="yes"/></td>
</tr>';
}
else
{
echo'
<td><input type="hidden" name="vragen'.$aantalBranches.'[]" value="'.$row1['vraag'].'"/></td>
<td><input type="text" name="antwoorden'.$aantalBranches.'[]" value="no"/></td>
</tr>';
}
$c++;
}
}
echo '</table>';
$aantalBranches++;
}
The problem is that i want the result stored in 1 variable the $antwoorden [] so the most logic way was a if else for this but for a strange reason it doesn’t work any1 can help me ?
It now only shows “no” even if i change it to “yes”.
I edited the script and added the other choises of the form long and short fields(textarea/inputfield)
Thanks in advance.
This part will always evaluate to false.
You probably don’t know how this variable is going to be named because name depends on value from variable $c and this is what is giving you difficulties.
To overcome this you could just pull all of the variables that start with ‘optie’ string and then cycle through them when you want to use them. You can also access this variable like this.
But generally speaking looking at your code it is very badly structured and I would consider restructuring that code. But without more context I can’t give you more instructions on how to do this.
Update:
Just change mentioned condition to:
Or change $_POST to $_GET if you are using ‘GET’ http request to pass ‘optie’ variables.