doulu1968 2016-07-21 06:20
浏览 7
已采纳

在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>
  • 写回答

2条回答 默认 最新

  • dougao1106 2016-07-21 06:23
    关注

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

     <? echo ($comment_order == "DESC" ? "selected" : "");?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部