This question already has answers here:
PHP with Bootstrap Carousel
(4 answers)
Closed 2 years ago.
i have a problem to do with Carousel Slider. i am adding an image and when i was listing in index.php. When i was adding and listing second image, it is adding just below as in pictures.
enter image description here
enter image description here
Slider.php
<?php
$veriler = $db->query("SELECT * FROM haberlerekle ORDER BY id DESC LIMIT 10",PDO::FETCH_ASSOC)->fetchAll();
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<?php $count = count($veriler);?>
<ul class="carousel-indicators">
<?php
$i=0;
for ($i=0;$i<$count;$i++) { ?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner">
<?php
$j=0;
foreach ($veriler as $row) { ?>
<div class="item <?php if($j==0) { echo "active"; } ?>">
<div style="max-width:1100px; max-height:500px;">
<img src=" <?php echo $row["haberekle_konu"]; ?>" alt="Los Angeles">
</div>
<div class="carousel-caption">
<h3> <?php echo $row["haberekle_baslik"]; ?> </h3>
</div>
</div>
<?php $j++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
Codes below.
<div id="demo" class="carousel slide" data-ride="carousel">
<?php
$veriler = $db->query("SELECT * FROM haberlerekle",PDO::FETCH_ASSOC)->fetchAll();
foreach ($veriler as $row) { ?>
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<div class="carousel-inner">
<div class="carousel-item active">
<div style="max-width:1100px; max-height:500px;"> <?php echo $row['haberekle_konu']; ?> </div>
<div class="carousel-caption">
<h3> <?php echo $row['haberekle_baslik']; ?> </h3>
</div>
</div>
<?php } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
admin.php -- a part of admin.php -- i think, all of the admin.php unnecessary. if it is important, now i can share.
<form>
<input name="haberekle_baslik" size="100"></input><br><br>
Başlık <br>
<textarea name="editor1" cols="150" rows="30"></textarea><br>
<input type="submit" name="submit" value="Yayınla" style="margin-top:5px;">
Yeni Ekle
</form>
<?php
if (isset($_REQUEST['editor1']) && !empty($_REQUEST['editor1'])) {
$baslik = $_REQUEST['haberekle_baslik'];
$content = $_REQUEST['editor1'];
} else {
echo "Lütfen Metin Alanını Doldurunuz";
}
if (isset($_REQUEST['submit'])) {
if (isset($content) && !empty($content)) {
}
}
$haberekle = $db->prepare("INSERT INTO haberlerekle (haberekle_baslik, haberekle_konu) VALUES (:baslik, :konu)");
$haberekle->bindValue(':baslik', $baslik, PDO::PARAM_STR);
$haberekle->bindValue(':konu', $content, PDO::PARAM_STR);
$isle = $haberekle->execute();
if($isle) echo 'ok';
else echo 'no';
?>
See i added images
For image store i selected "BLOB" but it doesn't work again.enter image description here
enter image description here
Thanks in advance
Below code is working with logics. Note: I have changed classname carousel-item to item.I hope it will help.
<?php
$veriler = $db->query("SELECT * FROM haberlerekle ORDER BY id DESC LIMIT 10",PDO::FETCH_ASSOC)->fetchAll();
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<?php $count = count($veriler);?>
<ul class="carousel-indicators">
<?PHP
$i=0;
for ($i=0;$i<$count;$i++) { ?>
<li data-target="#demo" data-slide-to="<?php echo $i; ?>"></li>
<?php } ?>
</ul>
<div class="carousel-inner">
<?php
$j=0;
foreach ($veriler as $row) { ?>
<div class="item <?php if($j==0) { echo "active"; } ?>">
<div style="max-width:1100px; max-height:500px;">
<img src=" <?php echo $row["haberekle_konu"]; ?>" alt="Los Angeles">
</div>
<div class="carousel-caption">
<h3> <?php echo $row["haberekle_baslik"]; ?> </h3>
</div>
</div>
<?php $j++; } ?>
</div>
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
Related
This question already has an answer here:
How do i fix this loop to display images from my database using bootstrap carousel
(1 answer)
Closed 3 years ago.
I want to display images using bootstrap carousel using foreach loop.
I have been having a difficult time trying to display images using foreach loop... Please note that my database functions are not the problem... I just need help to restructure the loop.
<?php
$message = "";
if(empty($_GET['id'])) {
$session->message("<div class='btn sm-warning'>please select an image.</div>");
redirect_to('list_properties.php');
}
$id = $_GET['id'];
$sql = "SELECT * FROM pictures2 WHERE photograph_id='$id';";
$photos = Picture::find_by_sql($sql);
?>
Truth is i am so confused right now. I just want to restructure this loop using foreach...
<div id="carouselExampleIndicators" class="carousel slide mx-auto" data-ride="carousel">
<ol class="carousel-indicators">
<?php $i=0; foreach($photos as $photo){?>
<?php if($i==0){ ?><li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>" class="active"><?php } ?>
<?php if($i % 2 == 0){ ?><li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>"><?php }?>
<?php if($i % 4 != 0){ ?></li><?php }?>
<?php $i++; } ?>
</li>
</ol>
<div class="carousel-inner">
<?php $i=0; foreach($photos as $photo){?>
<?php if($i==0){ ?><div class="carousel-item active"><?php } ?>
<?php if($i % 2 == 0){ ?><div class="carousel-item"><?php }?>
<div class="col-xs-3">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" height="500" width="500" alt=""/>
</div>
<?php if($i % 4 != 0){ ?></div><?php }?>
<?php $i++; } ?>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php
$message = "";
if(empty($_GET['id'])) {
$session->message("<div class='btn sm-warning'>please select an image.</div>");
redirect_to('list_properties.php');
}
$id = $_GET['id'];
$sql = "SELECT * FROM pictures2 WHERE photograph_id='$id';";
$photos = Picture::find_by_sql($sql);
?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
$i = 0;
foreach($photos as $photo){
if($i == 0){
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>" class="active"></li>
<?php
$i++; }else{
if($i != 0){
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>" ></li>
<?php
} $i++;
}
}
?>
</ol>
<div class="carousel-inner">
<?php
$i = 0;
foreach($photos as $photo){
if($i == 0){
?>
<div class="carousel-item active">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" height="500" width="500" alt="<?php echo $photo->title; ?>"/>
</div>
<?php
$i++; } else{
if($i != 0){
?>
<div class="carousel-item">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" height="500" width="500" alt="<?php echo $photo->title; ?>"/>
</div>
<?php
} $i++;
}
}
?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
I tried using bootstrap carousel to display images from my database but something seem to be wrong with my loop...
<?php
$message = "";
if(empty($_GET['id'])) {
$session->message("<div class='btn sm-warning'>please select an image.</div>");
redirect_to('list_properties.php');
}
$id = $_GET['id'];
$sql = "SELECT * FROM pictures2 WHERE photograph_id='$id';";
$photos = Picture::find_by_sql($sql);
?>
The fetch is all correct from the database but the loop displaying the images in the slide displays one image and the slide loops between the first and second slide only.
<div class="container">
<div class="row">
<div id="carouselExampleIndicators" class="carousel slide mx-auto" data-ride="carousel">
<ol class="carousel-indicators">
<?php
$i=0;
if(count($photos)){
foreach ($photos as $photo) {
if($i==0){
echo '<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>';
$i++;
}
else
{
echo '<li data-target="#carouselExampleIndicators" data-slide-to="0"></li>';
$i++;
}
}
}
?>
</ol>
<div class="carousel-inner">
<?php
$a=0;
if(count($photos)){
foreach ($photos as $photo) {
if($a==0){
?>
<div class="carousel-item active">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" alt="<?php echo $photo->title; ?>"/>
<?php
$a++;
}else
?>
</div>
<?php
{
?>
<div class="carousel-item">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" alt="<?php echo $photo->title; ?>"/>
<?php
$a++;
}
?>
</div>
<?php
}
}
?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
<?php
$message = "";
if(empty($_GET['id'])) {
$session->message("<div class='btn sm-warning'>please select an image.</div>");
redirect_to('list_properties.php');
}
$id = $_GET['id'];
$sql = "SELECT * FROM pictures2 WHERE photograph_id='$id';";
$photos = Picture::find_by_sql($sql);
?>
.
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
$i = 0;
foreach($photos as $photo){
if($i == 0){
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>" class="active"></li>
<?php
$i++; }else{
if($i != 0){
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $i; ?>" ></li>
<?php
} $i++;
}
}
?>
</ol>
<div class="carousel-inner">
<?php
$i = 0;
foreach($photos as $photo){
if($i == 0){
?>
<div class="carousel-item active">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" height="500" width="500" alt="<?php echo $photo->title; ?>"/>
</div>
<?php
$i++; } else{
if($i != 0){
?>
<div class="carousel-item">
<img src="<?php echo $photo->image_path(); ?>" class="img-thumbnail img-responsive" height="500" width="500" alt="<?php echo $photo->title; ?>"/>
</div>
<?php
} $i++;
}
}
?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
I currently trying to make it where My Database is storing image names like slider1.jpg and then I'm retrieving that from my database, but the issue is when I'm selecting * all from the table its only displaying the first link in the table. Any Ideas on how I can fix this in my code?
Heres my PHP:
<?php
//Gets Links
$stmt = $DB_con->prepare('SELECT * FROM slider');
$stmt->execute();
if($stmt->rowCount() > 0)
{
$row=$stmt->fetch(PDO::FETCH_ASSOC);
extract($row);
}
?>
And Heres my Carousel Slider.
<header>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<!-- Slide One - Set the background image for this slide in the line below -->
<div class="carousel-item active" style="background-image: url('images/slider/<?php echo $row['link'];?>')">
<div class="carousel-caption d-none d-md-block">
<h3>First Slide</h3>
<p>This is a description for the first slide.</p>
</div>
</div>
<!-- Slide Two - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('images/slider/<?php echo $row['link'];?>')">
<div class="carousel-caption d-none d-md-block">
<h3>Second Slide</h3>
<p>This is a description for the second slide.</p>
</div>
</div>
<!-- Slide Three - Set the background image for this slide in the line below -->
<div class="carousel-item" style="background-image: url('images/slider/<?php echo $row['link'];?>')">
<div class="carousel-caption d-none d-md-block">
<h3>Third Slide</h3>
<p>This is a description for the third slide.</p>
</div>
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</header>
You need to utilize a loop on the results so you can build each slide with a new $row from the database query:
<?php
// build a clean array of slides from the db grab
$stmt = $DB_con->prepare('SELECT * FROM slider');
$stmt->execute();
$slides = [];
if($stmt->rowCount() > 0) {
$slides = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
.... starter html ....
<ol class="carousel-indicators">
<?php foreach($slides as $i => $slide) { ?>
<li data-target="#carouselExampleIndicators"
data-slide-to="<?php echo $i;?>"
class="<?php echo (!$i?'active':'');?>"></li>
<?php }?>
</ol>
.... more html ....
<div class="carousel-inner" role="listbox">
<?php foreach($slides as $i => $slide) { ?>
<div class="carousel-item <?php echo (!$i?'active':'');?>"
style="background-image: url('images/slider/<?php echo $slide['link'];?>')">
<div class="carousel-caption d-none d-md-block">
<h3><?php echo $slide['slide_name'];?></h3>
<p><?php echo $slide['slide_desc'];?></p>
</div>
</div>
<?php } ?>
</div>
.... the rest of your html output ....
I am trying to modify an existing carousel by loading data from an SQL instead of hardcoding it. But, after fetching the data from SQL using PHP the controls of the carousel is not working.
When I checked the source, the contents of all slides are added correctly obtained from the database.
FYI - I also have another carousel on the same page which is working fine. So, I think all the requirements will be loaded correctly.
Below is my code:
<!-- Wrapper for Slides -->
<div class="carousel-inner">
<!-- Query from db -->
<?php
$sql='SELECT * FROM Books LIMIT 6';
$result = mysqli_query($con, $sql); ?>
<!-- start of while loop -->
<?php while($row = mysqli_fetch_array($result)) { ?>
<?php if ($row[bookID] == 1) echo '<div class="item active">';
else echo '<div class="item">'; ?>
<div class="fill" style="background-image: url('<?php echo $row[thumb]; ?>');">
<a href="books.php?page=<?php echo $row[bookID]; ?>" class="portfolio-box">
<img src="<?php echo $row[thumb]; ?>" class="img-responsive"
alt="<?php echo $row[name_small]; ?>">
<div class="portfolio-box-caption portfolio1">
<div class="portfolio-box-caption-content">
<div class="project-name">
<h4><strong><?php echo $row[name_small]; ?></strong>
<small><?php echo $row[second_title]; ?></small>
</h4>
<hr>
<p><?php echo $row[mini_desc]; ?></p>
<p><strong>First Published :</strong>
<?php echo $row[first_published]; ?></p>
</div>
</div>
</div>
</a>
</div><?php } ?>
<!-- end of while loop -->
</div>
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
<li data-target="#myCarousel" data-slide-to="3"></li>
<li data-target="#myCarousel" data-slide-to="4"></li>
<li data-target="#myCarousel" data-slide-to="5"></li>
</ol>
<!-- Controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
</a>
</div>
</section>
I tried comparing the code to my old carousel and everything looks the same. Can anyone tell me what I am doing wrong here?
Try this end of your loop:
</div><!--portfolio-box-caption-->
</a>
</div><!--fill-->
</div><!--item-->
<?php } ?><!-- end of while loop -->
Your condition
if($row[bookID] == 1)
It can or not have bookID equal to 1 in your database data !
To prevent it, use this
<?php $i = 1; while($row = mysqli_fetch_array($result)): ?>
<div class="item <?= ($i == 1) ? 'active' : '' ?>">
<div class="fill" style="background-image: url('<?php echo $row[thumb]; ?>');">
<a href="books.php?page=<?php echo $row[bookID]; ?>" class="portfolio-box">
<img src="<?php echo $row[thumb]; ?>" class="img-responsive"
alt="<?php echo $row[name_small]; ?>">
<div class="portfolio-box-caption portfolio1">
<div class="portfolio-box-caption-content">
<div class="project-name">
<h4><strong><?php echo $row[name_small]; ?></strong>
<small><?php echo $row[second_title]; ?></small>
</h4>
<hr>
<p><?php echo $row[mini_desc]; ?></p>
<p><strong>First Published :</strong>
<?php echo $row[first_published]; ?></p>
</div>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
I am using the advanced custom fields Wordpress plugin to create various slides for a slider. To display the slider I am using Bootstraps Carousel.
The body of the slider if functioning fine. I don't, however, know how to loop through, count the slides and print a carousel indicator to the page for each slide.
I currently have 3 hardcoded at the top of the slider.
<ul id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<li class="carousel-inner">
<?php
$c = 0;
$class = '';
while ( have_rows('slide') ) : the_row();
$c++;
if ( $c == 1 ){ $class = ' active';}
else{ $class=''; } ?>
<?php
$image = get_sub_field('image'); ?>
<div class="carousel-item <?php echo $class; ?> image" style="background: url('<?php echo $image; ?>') no-repeat; background-size: cover; background-position: left center;">
</div>
<?php
endwhile; ?>
</li> <!-- end li.image -->
</ul> <!-- end ul -->
I need to find a way to open the ordered list before the slider starts and close it when it ends. At the same time, I need to echo out its li elements for each slide.
<section id="banner">
<?php if( have_rows('slides') ) { ?>
<?php
$num = 0;
$active = 'active';
?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php while( have_rows('slides') ) : the_row() ; ?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?php echo $num; ?>" class="<?php echo $active; ?>"></li>
<?php
$num++;
$active = '';
?>
<?php endwhile; ?>
</ol>
<div class="carousel-inner">
<?php $active = 'active'; ?>
<?php while( have_rows('slides') ) : the_row() ;
$image = get_sub_field('image');
$mainText = get_sub_field('main_text');
$subText = get_sub_field('sub_text');
?>
<div class="carousel-item <?php echo $active; ?>">
<img class="d-block w-100" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<div class="carousel-caption d-none d-md-block">
<h5><?php echo $mainText; ?></h5>
<p><?php echo $subText; ?></p>
</div>
</div>
<?php $active = ''; ?>
<?php endwhile; ?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<?php } ?>
</section>
If your HTML is like this :
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="d-block img-fluid" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block img-fluid" src="..." alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
Then use this php code :
<?php
$sliders = get_field('slide');
if($sliders){ ?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php $isActive ='';
foreach($sliders as $key=>$slider){
if($key==0){
$isActive = 'active';
}
echo '<li data-target="#carouselExampleIndicators" data-slide-to="'.$key.'" class="'.$isActive.'"></li>';
} ?>
</ol>
<div class="carousel-inner" role="listbox">
<?php
$activeSlide ='';
foreach($sliders as $key=>$sliderimg){
if($key==0){
$activeSlide = 'active';
}
echo '<div class="carousel-item '.$activeSlide.'">';
echo '<img class="d-block img-fluid" src="'.$sliderimg['image']." alt="First slide">';
echo '</div>';
?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
<?php } ?>