duanca3415 2018-06-19 15:17
浏览 270
已采纳

解析错误:语法错误,意外'elseif',多个elseif [重复]

This question already has an answer here:

Here is my code :

<?php
   if ($data[0][extraUrbanKmConsumption]<85 AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/A.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=85 AND $data[0][extraUrbanKmConsumption]<115  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/B.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=115 AND $data[0][extraUrbanKmConsumption]<145  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/C.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=145 AND $data[0][extraUrbanKmConsumption]<175  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/D.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=175 AND $data[0][extraUrbanKmConsumption]<205  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/E.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=205 AND $data[0][extraUrbanKmConsumption]<235  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/F.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?> 
  <?php elseif ($data[0][extraUrbanKmConsumption]>=235  AND $data[0][energy][name] == "Diesel") { ?>
    <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/G.png" class="img-fluid" alt="Responsive image"></h5>
    <?php } ?>

that return me this error : Parse error: syntax error, unexpected 'elseif' (T_ELSEIF), expecting end of file

where my syntax is wrong?

</div>
  • 写回答

1条回答 默认 最新

  • dougou8639 2018-06-19 15:20
    关注

    The problem is that, you don't break the PHP parser before elseif or else. It's similar to having an echo in between them, which makes it a Syntax Error. Use this way:

    <?php
      if ($data[0][extraUrbanKmConsumption]<85 AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/A.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=85 AND $data[0][extraUrbanKmConsumption]<115  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/B.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=115 AND $data[0][extraUrbanKmConsumption]<145  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/C.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=145 AND $data[0][extraUrbanKmConsumption]<175  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/D.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=175 AND $data[0][extraUrbanKmConsumption]<205  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/E.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=205 AND $data[0][extraUrbanKmConsumption]<235  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/F.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } elseif ($data[0][extraUrbanKmConsumption]>=235  AND $data[0][energy][name] == "Diesel") { ?>
        <h5 class="text-light">Emission de cO2 : <?php echo $data[0][extraUrbanKmConsumption]; ?> <img src="icone c02/G.png" class="img-fluid" alt="Responsive image"></h5>
      <?php } ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?