我有这个代码从数据库中获取旋转木马图像或视频
$stmt = $con->prepare("SELECT * FROM `Main`");
$stmt->execute();
$rows = $stmt->fetchAll();
return $rows;
这个代码显示旋转木马
它必须只显示IMG或位于数据库中的视频
<?php
$check = $pageClass->mainPage("check");
if ($check > 0) {
$sliders = $pageClass->mainPage("select","Slider");
$allowedImg = array("png","jpg","jpeg","bmp","gif");
$allowedVideo = array("mp4","mkv","flv","avi","3gp");
?>
<section class="clients-opinion">
<div class="container">
<header class="text-center">
<h3 class="h1">See what our graduates are <br />saying about the plan</h3>
</header>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
for ($i = 0;$i < count($sliders);$i++) {
if ($i == 0) {?>
<li data-target="#myCarousel" data-slide-to="<?php echo $i; ?>" class='active'></li>
<?php } else { ?>
<li data-target="#myCarousel" data-slide-to="<?php echo $i; ?>"></li>
<?php }
}?>
</ol>
<div class="carousel-inner">
<?php
foreach ($sliders as $slider) {
for ($i = 0; $i < count($sliders); $i++) {
if ($i == 0) {?>
<div class="item active">
<?php
$explodedSlider = explode(".", $slider['Slider']);
$sliderType = strtolower(end($explodedSlider));
if (in_array($sliderType, $allowedImg)) {?>
<img src="<?php echo $imgUploads . $slider['Slider']; ?>" alt="">
<?php } else if (in_array($sliderType, $allowedVideo)) { ?>
<video controls="controls">
<source src="<?php echo $vidUploads . $slider['Slider']; ?>" type="video/<?php echo $sliderType; ?>" />
</video>
<?php } ?>
</div><?php
} else {?>
<div class="item">
<?php
$explodedSlider = explode(".", $slider['Slider']);
$sliderType = strtolower(end($explodedSlider));
if (in_array($sliderType, $allowedImg)) {?>
<img src="<?php echo $imgUploads . $slider['Slider']; ?>" alt="">
<?php } else if (in_array($sliderType, $allowedVideo)) { ?>
<video controls="controls">
<source src="<?php echo $vidUploads . $slider['Slider']; ?>" type="video/<?php echo $sliderType; ?>" />
</video>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
<?php } ?>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</section>
但是,这是9个IMG,
而我的数据库里只有3个img。
求求你,救命!
提前谢谢!
1条答案
按热度按时间zy1mlcev1#
您正在使用
for
a内循环foreach
,这样就可以了3x3
,因此是9。只需移除
for
循环。