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

解析错误:语法错误,意外'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
    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 } ?>
    
    点赞 评论

相关推荐