Q:

how to use sql fields in a slideshow

this is the html code of the slideshow:
<div class="bg-faded p-4 my-4">
  <hr class="divider">
  <h2 class="text-center text-lg text-uppercase my-0"><strong>Notícias</strong></h2>
  <hr class="divider">
  <div class="bg-faded p-4 my-4">
    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner" role="listbox">
        <div class="carousel-item active">
          <img class="img-fluid float-left mr-4 d-none d-lg-block" src="img/noticia1.jpg" alt="" style="max-width: 250px; max-height: 150px;">
          <p>A Fidelidade brilhou na Web Summit 2017 com o programa Protechting by Fosun & Fidelidade e atraiu cerca de 180 novas candidaturas de startups! Um número promissor que confirma o prestígio associado a esta iniciativa, bem como o nosso compromisso com o empreendedorismo, a inovação tecnológica e o desenvolvimento do País. Obrigado a todos que estiveram connosco nestes dias!</p>
        </div>
        <div class="carousel-item">
          <img class="img-fluid float-left mr-4 d-none d-lg-block" src="img/noticia2.png" alt="" style="max-width: 250px; max-height: 150px;">
          <p>Agora já não precisa de sair de casa para ir ao médico. Vá por telefone ou vídeo.</p>
        </div>
      </div>
    </div>
  </div>
</div>

and i tried to use sql fields in this slideshow:
<div class="bg-faded p-4 my-4">
      <!-- Image Carousel -->
      <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner" role="listbox">
          <?php
            require_once "conexao.php";
            $conexao = conexao_db();
            $sql = mysqli_query($conexao, "SELECT * FROM noticias");
            $row = mysqli_num_rows($sql);
            if ($row>0) {
                while ($registo = mysqli_fetch_array($sql)) {
                extract($registo);
                echo "<div class='carousel-item active'>
                  <img class='img-fluid float-left mr-4 d-none d-lg-block' src='img/".$no_img."' alt='' style='max-width: 250px; max-height: 150px;'>
                  <p>".$no_noticia."</p>
                </div>";
              }
            }
          ?>
        </div>
      </div>
    </div>

but how you see, the first slide of the slideshow needs to have the "active" in the div class, but the rest do not. how do i do this using php?

A:

You can use a variable to control if it is the first slide or not:
<div class="bg-faded p-4 my-4">
  <!-- Image Carousel -->
  <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner" role="listbox">
      <?php
        require_once "conexao.php";
        $conexao = conexao_db();
        $sql = mysqli_query($conexao, "SELECT * FROM noticias");
        $row = mysqli_num_rows($sql);
        if ($row>0) {
            $isFirstSlide = true;
            while ($registo = mysqli_fetch_array($sql)) {
                extract($registo);

                $class = '';
                if($isFirstSlide){
                   $class = ' active';
                }

                echo "<div class='carousel-item".$class."'>
                  <img class='img-fluid float-left mr-4 d-none d-lg-block' src='img/".$no_img."' alt='' style='max-width: 250px; max-height: 150px;'>
                  <p>".$no_noticia."</p>
                </div>";
                $isFirstSlide = false;
            }
        }
      ?>
    </div>
  </div>
</div>

