CodeIgniter Forums
form_radio problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: form_radio problem (/showthread.php?tid=12008)



form_radio problem - El Forum - 10-01-2008

[eluser]Kfrico[/eluser]
Code:
$abc = 'a';
   echo '狀態: ';
   echo form_radio('Status', 'a',if($abc == 'a')echo TRUE;);

Parse error: syntax error, unexpected T_IF in

WHY?


form_radio problem - El Forum - 10-02-2008

[eluser]xwero[/eluser]
You can't add a control structure as a parameter. and using echo makes it even worse as it outputs the value.


form_radio problem - El Forum - 10-02-2008

[eluser]Bogdan Tanase[/eluser]
right!

I think you could write it like this:

Code:
echo form_radio('Status','a',($abc=='a')?TRUE:FALSE);



form_radio problem - El Forum - 10-02-2008

[eluser]Pascal Kriete[/eluser]
($abc == 'a') is already a boolean expression.
Code:
echo form_radio('Status','a', ($abc=='a') );



form_radio problem - El Forum - 10-02-2008

[eluser]Kfrico[/eluser]
thanks


form_radio problem - El Forum - 10-02-2008

[eluser]Bogdan Tanase[/eluser]
[quote author="inparo" date="1222976498"]($abc == 'a') is already a boolean expression.
[/quote]

True, but I wanted to exemplify the use of the ternary operator instead of if control structure