[带条件在PHP内加载Div HTML代码

问题描述 投票:0回答:1

我正在从数据库获取图像,并希望使用HTML和PHP代码在滑块中显示该图像。我有示例滑块的HTML代码,如下所示

  <div class="carousel-inner">
    <div class="item active">
     <img class="img-responsive" src="http://placehold.it/1200x600/555/000&text=One" alt="...">
      <div class="carousel-caption">
        One Image
      </div>
    </div>
    <div class="item">
      <img class="img-responsive" src="http://placehold.it/1200x600/fffccc/000&text=Two" alt="...">
      <div class="carousel-caption">
        Another Image
      </div>
    </div>
     <div class="item">
      <img class="img-responsive" src="http://placehold.it/1200x600/fcf00c/000&text=Three" alt="...">
      <div class="carousel-caption">
        Another Image
      </div>
    </div>
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left"></span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right"></span>
  </a>
</div>
    </div>
  </div>
</div>

它工作正常,但使用占位符图像,我希望从数据库中获取图像,如下面的PHP代码

 <?php 

 $i= 0; 

 if(!empty($images)){ foreach($images as $image){ $i++;

    echo $image->title;
    echo $image->file_name;
     }
 }



 ?>

我想要第一个图像,然后是所有其他图像。我是PHP新手,所以很困惑如何做,请告诉我是否有PHP专家可以帮助我。谢谢!

php html
1个回答
0
投票

非常简单:您必须遍历图像并为循环中的每个图像打印转盘div

© www.soinside.com 2019 - 2024. All rights reserved.