my dynamic bootstrap carousel does not work for me

0

I'm having a problem, I try to show on a bootstrap carousel the images of a directory, but it does not work because it puts them all as active items, and I do not find the error in my code. Someone to help me ...

<div id="imagenes" class="carousel slide" data-ride="carousel">
     <div class="carousel-inner">
     <?php  $path = 'images/art/'.$id;
     if (file_exists($path)){
         $directorio = opendir($path);
         $i=1;
         while (false !== ($archivo = readdir($directorio))){
             if (!is_dir($archivo)){
                 if ($i=1){ 
                     echo "<div class='item active'><img src='images/art/$id/$archivo' style='max-width: 300px; max-height: 300px' /></div>";
                 } else {
                     echo "<div class='item'><img src='images/art/$id/$archivo' style='max-width: 300px; max-height: 300px' /></div>";
                 }
                 $i++;
             }
         }
     } ?>
     </div>

     <a class="left item-control" href="#imagenes" data-slide="prev">
         <i class="fa fa-angle-left"></i>
     </a>
     <a class="right item-control" href="#imagenes" data-slide="next">
         <i class="fa fa-angle-right"></i>
     </a>
</div>
    
asked by Maite 03.07.2018 в 17:21
source

1 answer

0

I just saw the error in the if

must be if (1 === $i) or if (1 == $i) you can also put the variable before but putting the number before you avoid accidental association

=== = identical

== = equal

= = associate value

Here is some information about the conditions "Yoda"

  

link

    
answered by 03.07.2018 / 17:36
source