Richard Young Richard Young - 8 months ago 58
PHP Question

Ternary toggle in php

I'm trying to set the order of something using options from a dropdown. I'm putting the order into a variable and I'm trying to use that variable to decide which option to have as selected but for some reason it won't work. Can anyone work out what I'm doing wrong please?

<option value="DESC" <? ($comment_order == "DESC" ? "selected" : "");?>>Descending</option>
<option value="ASC" <? ($comment_order == "ASC" ? "selected" : "");?>>Ascending</option>


Your statement does not output anything. You want to put echo before it:

 <? echo ($comment_order == "DESC" ? "selected" : "");?>