Clicking on the "Show more" button only has 1 more result

1

I made a list in which initially 6 elements 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>

The js button code is as follows:

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

The following is an image of the listing:

ButwhenIclickthe"show more categories" button, only one element appears. Thank you.

    
asked by anonymous 05.05.2016 / 13:27

1 answer

1

It should be because you are creating several div's with the same id="photos" inside your loop, try 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>

So, it will create a single div with the id="photos" and the loop mounts several div's with the items inside it. I have not tested it, but I believe it to be.

Hope it helps

health and peace!

    
05.05.2016 / 13:50