douyong1885 2013-07-30 00:24
浏览 30
已采纳

IF ELSE STATEMENT跨度样式PHP [关闭]

Hi, I'm changing the color of the text in the table according to its value... if the value is "posted" then its color is blue if it's "cancel" it's red...

I have been able to achieve it using an if statement:

<td><span style="<?php if($value['posted'] == 'posted')echo 'color:blue'?>"><?php echo $value['posted']; ?></span></td>

When I add an ELSE IF for the cancel I figured out that it should look like this;

<td><span style="<?php 
if($value['posted'] == 'posted')
{
echo 'color:blue'
} 
else if($value['posted'] == 'cancel')
{
   echo 'color:red'
}
?>">
<?php echo $value['posted']; ?></span></td>

But it's SYNTAX ERROR UnEXPECTED }

I know it's just a simple else if statement but I can't get it right. Please help...

  • 写回答

2条回答 默认 最新

  • duan7264 2013-07-30 00:25
    关注

    You need semicolons after your echo:

    if($value['posted'] == 'posted')
    {
       echo 'color:blue';//<-- right here
    } 
    else if($value['posted'] == 'cancel')
    {
       echo 'color:red';//<-- right here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码