I have made a dynamic bootstrap slider according the data fetched from database in php. Here I want to display 3 grid per slider, it works completely. But I just want to create a 3 grid in a single row. Here i got the grid in new row. What I have to do to get the 3 grid in a single row?
<div class="container content">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
</ol>
<div class="col-lg-12">
<h1><center>Client Reviews</center></h1>
</div>
<div class="carousel-inner">
<?php
foreach($hello as $review){
?>
<?php if ($i % 3 == 0):?>
<div class="item<?php if ($is_active) echo ' active'?>">
<?php endif?>
<div class="row">
<div class="col-xs-12" style="margin:35px;">
<div class="col-md-4">
<div class="caption">
<p class="text-info lead adjust2"><?php echo $review\['testimonial'\];?></p>
<p><span class="glyphicon glyphicon-minus"></span> <?php echo $review\['name'\];?></p>
</div>
</div>
</div>
</div>
<?php if (($i+1) % 3 == 0 || $i == count($review)-1):?>
</div>
<?php endif?>
<?php
$i++;
if ($is_active) $is_active = false;
};
?>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span> </a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span> </a>
</div>
</div>
I think u open add before loop.
[![<div class="container content">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
</ol>
<div class="col-lg-12">
<h1><center>Client Reviews</center></h1>
</div>
<div class="carousel-inner">
<div class="row">
<div class="col-xs-12" style="margin:35px;">
<?php
foreach($hello as $review){
?>
<?php if ($i % 3 == 0):?>
<div class="item<?php if ($is_active) echo ' active'?>">
<?php endif?>
<div class="col-md-4">
<div class="caption">
<p class="text-info lead adjust2"><?php echo $review\['testimonial'\];?></p>
<p><span class="glyphicon glyphicon-minus"></span> <?php echo $review\['name'\];?></p>
</div>
</div>
<?php if (($i+1) % 3 == 0 || $i == count($review)-1):?>
</div>
<?php endif?>
<?php
$i++;
if ($is_active) $is_active = false;
};
?>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span> </a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span> </a>
</div>
</div>
</div>
</div>][1]][1]
Related
enter image description hereHere is the output I have tried this code but the carousel is not working properly...The first image is shown properly but the second one is shown below the first one and not in slides....Here is my code..
<div class="banner">
<?php
mysqli_set_charset($conn, 'utf8');
$query=mysqli_query($conn,"select * from post_tbl where status='Approved' Order by pid DESC");
while($row=mysqli_fetch_array($query))
{
?>
<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>
<li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<div class="carousel-caption">
<h3><?php echo $row['title']; ?>
</h3>
<div class="read">
Read More
</div>
</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>
<?php } ?>
</div>
You will need 2 loops. One to know how many rows you are going to draw. This will be used to build your ol DOM.
The second to loop your actual div content where your select contains the necessary information.
<div class="banner">
<?php
mysqli_set_charset($conn, 'utf8');
$query = mysqli_query($conn, "select * from post_tbl where status='Approved' Order by pid DESC");
?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<?php for ($numElements = 0; $numElements < mysqli_num_rows($query); $numElements++) : ?>
<li data-target="#carouselExampleIndicators"
data-slide-to="<?php echo $numElements ?>" <?php echo($numElements == 0 ? 'class="active"' : '') ?> ></li>
<?php endfor; ?>
<div class="carousel-inner" role="listbox">
<?php $rows = mysqli_fetch_array($query); ?>
<?php foreach ($rows as $row) : ?>
<div class="carousel-item <?php echo($row == reset($rows) ? 'active' : '') ?>">
<div class="carousel-caption">
<h3><?php echo $row['title']; ?>
</h3>
<div class="read">
Read More
</div>
</div>
</div>
<?php endforeach; ?>
</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>
This should set your DOM correctly.
If you are already familiar with OOP concepts this gets way more organised and protected and would highly advice to follow that route instead.
Also there are plenty of threads around warning about sql injection so, if you are thinking on having a variable to dynamically adjust your query, please look into those first
As an introduction I can leave you with this thread
Here is my Bootstrap ui that the data is fetched from the database. As you can see, the carousel is going down and cannot click next it just goes down. from the page.
1
please see the image above
data that I'm fetching are texts and not image
and here is my code
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Carousel 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>
</ol>
<?php
$dataid;
$data = mysqli_query($con,"SELECT * FROM feedback");
$count = mysqli_num_rows($data);
if ($count != 0) {
echo '
<div class="row ">';
while($row = mysqli_fetch_array($data)) {
echo '
<!-- Wrapper for carousel items -->
<div class="carousel-inner">
<div class="item carousel-item active">
<p class="testimonial">'. $row['comment'] .'</p>
<p class="overview"><b>Anonymous</b></p>
<div class="star-rating">
<ul class="list-inline">
<li class="list-inline-item"><i class="fa fa-heart" ></i></li>
<li class="list-inline-item"><i class="fas fa-thumbtack" ></i></li>
<li class="list-inline-item"><i class="fas fa-archive"></i></li>
<li class="list-inline-item"><i class="fa fa-trash" ></i></li>
<li class="list-inline-item"><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
</div>
';
}
}
?>
<!-- Carousel controls -->
<a class="carousel-control left carousel-control-prev" href="#myCarousel" data-slide="prev">
<i class="fa fa-angle-left"></i>
</a>
<a class="carousel-control right carousel-control-next" href="#myCarousel" data-slide="next">
<i class="fa fa-angle-right"></i>
</a>
</div>
</div>
The carousal structure is like
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="Third slide">
</div>
</div>
</div>
so you need to repeat the carousel-item
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php while($row = mysqli_fetch_array($data)) { ?>
<div class="carousel-item">
<img class="d-block w-100" src="..." alt="First slide">
</div>
<?php } ?>
</div>
</div>
If you need to display the text in the Carousel that comes from database then just give some padding and background-color to the Image
<div class="carousel-item active">
<img src="<?php echo imageSrcFromDb; ?>" width="1100" height="500">
<div class="carousel-caption">
<h3><?php echo ; //Your Heading text ?></h3>
<p><?php echo ; //Some description ?></p>
</div>
</div>
<!-- Wrapper for carousel items -->
<div class="carousel-inner">
<?php
while($row = mysqli_fetch_array($data)) {
echo '
<div class="item carousel-item">
<p class="testimonial">'. $row['comment'] .'</p>
<p class="overview"><b>Anonymous</b></p>
<div class="star-rating">
<ul class="list-inline">
<li class="list-inline-item"><i class="fa fa-heart" ></i></li>
<li class="list-inline-item"><i class="fas fa-thumbtack" ></i></li>
<li class="list-inline-item"><i class="fas fa-archive"></i></li>
<li class="list-inline-item"><i class="fa fa-trash" ></i></li>
<li class="list-inline-item"><i class="fa fa-star-o"></i></li>
</ul>
</div>
</div>
';
}
?>
</div>
the while loop should be inside the class carousel-inner .
My website already connect with database, but somehow bootstrap carousel that I use for slider not working... What I expected the image will be like this:
< image > < image > < image >
But what I get is:
<image>
<image>
<image>
I don't know what's wrong with my code... Can somebody help me?
<!--- Slider -->
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<?php foreach ($slider as $slider): ?>
<div class="item active">
<img src="<?php echo base_url('upload/slider/'.$slider->image)?>">
<div class="carousel-caption">
<h3><?php echo $slider->name?></h3>
</div>
</div>
<?php endforeach; ?>
</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>
I use this and work fine.
<div id="myCarousel" class="carousel slide" data-ride="carousel" >
<ol class="carousel-indicators">
<?php for($j=0; $j<count($slider); $j++) {?>
<li data-target="#myCarousel" data-slide-to="<?php echo $j; ?>" class=""></li>
<?php }; ?>
</ol>
<div class="carousel-inner" role="listbox" >
<?php $i=1;
foreach ($slider as $slider) { ?>
<div class="item <?php echo ($i==1) ? "active" : "" ?>">
<img src="<?php echo base_url('upload/slider/'.$slider->image) ?>" alt="" class="img-responsive" style="width:100%" title="">
<div class="carousel-caption">
<h3><?php echo $slider->name?></h3>
</div>
</div>
<?php $i++; } ?>
</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 class="carousel-line"></div>
</div>
How to loop the data? All image are displaying at one slide other slides are empty.
<div class="container">
<br>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- 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>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php foreach($banner as $data) { ?>
<div class="item active">
<img src="<?php echo base_url()?>uploads/banner/<?php echo $data['image']?>" alt="Chania" width="460" height="345">
</div>
<?php }?>
<div class="item">
<img src="<?php echo base_url()?>assets/image/c.jpg" alt="Chania" width="460" height="345">
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
How to loop the data? All image are displaying at one slide other slides are empty.
Use the below code.
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$i = 0;
foreach($banner as $data) { ?>
<div class="item <?php echo $i==0 ? 'active' : ''; $i++; ?>">
<img src="<?php echo base_url()?>uploads/banner/<?php echo $data['image']?>" alt="Chania" width="460" height="345">
</div>
<?php }?>
</div>
I want to show on a carousel/slider the photos related to the last 3 posts that have been made on my page.
The $last3 variable gets the last three posts:
<div class="row carousel-holder">
<div class="col-md-12">
<div id="carousel-example-generic" class="product carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
#foreach($last3 as $post)
<div class="item active">
<div class="fill" style="background-image:url('../../images/Blog/{{$post->photo}}');"></div>
<h2>{{$post->title}}</h2>
</div>
#endforeach
</div>
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
</a>
</div>
</div>
</div>