Clicking on "Show More" button displays only 1 more result

Asked

Viewed 711 times

1

I made a list in which 6 elements initially appear and when you click on a button 4 more appear. The database only has 10 elements. the code is:

<div class="row">
                <?php
            $query=mysqli_query($db,"select id_album, nome, foto from albuns order by id_album ASC limit 6");
             while($cat=mysqli_fetch_assoc($query)){?>
                    <div class="col-md-6">
                        <div class="portfolio-item">
                        <p class="imgDescription"> <?php echo $cat['nome'];?> </p>
                            <a>
                                <img class="img-portfolio img-responsive" src="<?php echo $cat['foto'];?>" onClick="location.href='listagem_album.php?id=<?php echo $cat['id_album'];?>'">
                            </a>
                        </div>
                    </div>
                    <?php } ?>

             <?php
            $query=mysqli_query($db,"select id_album, nome, foto from albuns order by id_album DESC limit 4");
             while($cat=mysqli_fetch_assoc($query)){?>
                    <div class="col-md-6" id="fotos" style="display:none">
                        <div class="portfolio-item">
                        <p class="imgDescription"> <?php echo $cat['nome'];?> </p>
                            <a>
                                <img class="img-portfolio img-responsive" src="<?php echo $cat['foto'];?>" onClick="location.href='listagem_album.php?id=<?php echo $cat['id_album'];?>'">
                            </a>
                        </div>
                    </div>
                   <?php } ?>
                </div>
                <div id="button"><a class="btn btn-dark">View More Categories</a></div>

js button code is as follows:

 <script>
$("button").click(function(){
                $("#fotos").fadeIn(); });
</script>

Below is an image of the listing:

inserir a descrição da imagem aqui

But when I click on the "show more Categories" button only one element appears. Thank you.

1 answer

1


It must be because so, Voce is creating several div’s with the same id="photos" inside your loop, tries to do so ó:

     $query=mysqli_query($db,"select id_album, nome, foto from albuns order by id_album DESC limit 4");
     <div class="col-md-6" id="fotos" style="display:none">
         while($cat=mysqli_fetch_assoc($query)){?>
           <div class="portfolio-item">
              <p class="imgDescription"> <?php echo $cat['nome'];?> </p>
              <a><img class="img-portfolio img-responsive" src="<?php echo $cat['foto'];?>" onClick="location.href='listagem_album.php?id=<?php echo $cat['id_album'];?>'"></a>
           </div>
         <?php } ?>
         <div id="button"><a class="btn btn-dark">View More Categories</a></div>
      </div>

dai, thus, will create a single div with id="photos" and the loop mounts several div’s with the items inside it.
I didn’t test it, but I believe that’s it.

I hope it helps

health and peace!

  • Good @Armando , worked! Before while I created a div without class, only with id="photos". And after while I kept the div class="col-Md-6" for css reasons. Thanks

  • Opa Claudia, but you can create with class Tbn will not affect anything for jquery because you are using the "ID" of div, but will affect everything in your layout with bootstrap.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.