CodeIgniter Forums
use of array data in views - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: use of array data in views (/thread-1798.html)



use of array data in views - El Forum - 06-27-2007

[eluser]pmonty[/eluser]
My array looks like this:
Quote:$formdata('sort'=>'perf-desc')
I am loading the view like this:
Quote:$this->load->view('testform',$formdata);
My view code looks like this:
Quote:Sort By: <select name="sorton">
<option value="perf-desc" &lt;?= if ($sort =="perf-desc") ? "selected='selected'" : "selected=''";?&gt; >Perf Desc</option>
</select>
Obviously I am doing something syntactically wrong to get this error:
Quote:Parse error: syntax error, unexpected T_IF in \system\application\views\testform.php on line 10

How should this be coded?

Paul


use of array data in views - El Forum - 06-27-2007

[eluser]kgill[/eluser]
You're mixing the two ways to write conditional logic... Since you're using the ternary operator the if is implied, remove it and it the parser will stop complaining it's finding an IF when it wasn't supposed to.


use of array data in views - El Forum - 06-27-2007

[eluser]pmonty[/eluser]
That did it. Thanks so much.