Display first image of a dynamic table in php

1

I would like to know how to display the first image of my MySQL table?

I used a dynamic input file, so I can have multiple names saved in a single table that in this case is the image. However, I'd like to know how I display only the first one?

The names in the DB are separated by ;

<div class="lista-prod col-lg-12 ">
<?php 
   $verificaQuery = mysqli_query($conexao,"select * from produtos");
   $verificaRow = mysqli_num_rows($verificaQuery);

       if ($verificaCount = 0) {

       } else {
           $contProd=0;
           while ($contSql = mysqli_fetch_array($verificaQuery)) {
            $contProd++;
       ?>
<div class="row mt-5">
<div class="col-lg-4">
   <img src="../imagens/produtos/<?php echo $contSql['imagem'];  ?>" style="width:100%;">
</div>

If I register only one image, it appears normally, but if I register more, it disappears. To summarize, I have a product page, the first image is the one that gets sample if the person opens the product, displays the other photos on the side, how do I control this?

    
asked by anonymous 12.10.2018 / 20:14

1 answer

2

Even with the response of the comment, I will leave below another example of code with greater organization:

<div class="lista-prod col-lg-12 ">
    <?php 
        $verificaQuery = mysqli_query($conexao,"select * from produtos");
        $verificaRow = mysqli_num_rows($verificaQuery);
        if ($verificaRow != 0) {    
           while ($contSql = mysqli_fetch_array($verificaQuery)) {
              $arrayDeImagens = explode(';', $contSql['imagem']);
              $primeiraImagem = $arrayDeImagens[0];
              echo "<div class='row mt-5'>
                       <div class='col-lg-4'>
                           <img src='../imagens/produtos/$primeiraImagem' style='width:100%;'>
                       </div>
                    </div>"; 
           }
        }            
    ?>
</div>

The code will print the HTML with the src of the tag img being the first image of each line returned

    
12.10.2018 / 22:09