title: How do i fix this loop to display images from my database using bootstrap carousel
body: <p>I tried using bootstrap carousel to display images from my database but something seem to be wrong with my loop...</p>
  
  <pre><code>&lt;?php
    $message = "";
    if(empty($_GET['id'])) {
      $session-&gt;message("&lt;div class='btn sm-warning'&gt;please select an image.&lt;/div&gt;");
      redirect_to('list_properties.php');
    } 
    $id      = $_GET['id'];
    $sql     = "SELECT * FROM pictures2 WHERE photograph_id='$id';";
    $photos = Picture::find_by_sql($sql);
  ?&gt;
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;div class="row"&gt;
  &lt;div id="carouselExampleIndicators" class="carousel slide mx-auto" data-ride="carousel"&gt;
    &lt;ol class="carousel-indicators"&gt;
      &lt;?php 
       $i=0;
      if(count($photos)){
          foreach ($photos as $photo) {
              if($i==0){
                  echo '&lt;li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"&gt;&lt;/li&gt;';
                  $i++;
              }
              else
              {
                  echo '&lt;li data-target="#carouselExampleIndicators" data-slide-to="0"&gt;&lt;/li&gt;';
                  $i++;
              }
          }
      }
     ?&gt;
    &lt;/ol&gt;
    &lt;div class="carousel-inner"&gt;
     &lt;?php
      $a=0;
      if(count($photos)){
          foreach ($photos as $photo) {
              if($a==0){
                  ?&gt;
              &lt;div class="carousel-item active"&gt;
             &lt;img src="&lt;?php echo $photo-&gt;image_path(); ?&gt;" class="img-thumbnail img-responsive"  alt="&lt;?php echo $photo-&gt;title; ?&gt;"/&gt;
              &lt;?php   
                  $a++;
              }else
              ?&gt;
      &lt;/div&gt;
             &lt;?php
              {
                  ?&gt;
              &lt;div class="carousel-item"&gt;
             &lt;img src="&lt;?php echo $photo-&gt;image_path(); ?&gt;" class="img-thumbnail img-responsive" alt="&lt;?php echo $photo-&gt;title; ?&gt;"/&gt;
                 &lt;?php
                  $a++;
              }
              ?&gt;
      &lt;/div&gt;
         &lt;?php
          }
      }
     ?&gt;
    &lt;/div&gt;
    &lt;a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"&gt;
      &lt;span class="carousel-control-prev-icon" aria-hidden="true"&gt;&lt;/span&gt;
      &lt;span class="sr-only"&gt;Previous&lt;/span&gt;
    &lt;/a&gt;
    &lt;a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"&gt;
      &lt;span class="carousel-control-next-icon" aria-hidden="true"&gt;&lt;/span&gt;
      &lt;span class="sr-only"&gt;Next&lt;/span&gt;
    &lt;/a&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>