doufu8588 2016-04-17 15:11
浏览 69
已采纳

三元运营商报价问题

I'm trying to display a default image in a HTML page in case the original one is not available.

I'm using a ternary operator as the condition is inside an "echo" but I'm having some issues I think with quotes.

The below code doesn't give me an error but instead of displaying the image, it shows the name of the jpg file in text format in the HTML page

<?php
    if ($result10->num_rows > 0) {
       while($row = $result10->fetch_assoc()) {
          echo "<div id='slider-property' class='carousel slide' data-ride='carousel'>
        <ol class='carousel-indicators'>
        <li data-target='#slider-property' data-slide-to='0' class=''>
        " . $row['FotoPrincipale'] . " == '' ? <img src='backup/images/com_jea/images/profile.jpg' alt=''> : <img src='backup/images/com_jea/images/". $row['Main Image'] . "' alt=''>
                                      </li>

Could someone help?

Thank you

  • 写回答

1条回答 默认 最新

  • douya5331 2016-04-17 15:31
    关注

    You could try to do the ternary operator outside the echo. It would look like this

    <?php
    if ($result10->num_rows > 0) {
       while($row = $result10->fetch_assoc()) {
          $src = $row['FotoPrincipale'] == '' ? 'backup/images/com_jea/images/profile.jpg' : 'backup/images/com_jea/images/'. $row['Main Image'];
          echo "<div id='slider-property' class='carousel slide' data-ride='carousel'>
          <ol class='carousel-indicators'>
          <li data-target='#slider-property' data-slide-to='0' class=''>
              <img src='".$src."' alt=''>
          </li>";
       }
    }    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚