Link images to category

0

I'm developing a slideshow based on categories. That is, categories are pulled from the database and images are attached to them. However, I'm having 2 problems. The first is the miniatures of the categories. One or more category thumbnails appear repeated (2 or 3 times) while other categories are not displayed.

The code is:

echo '<h2 class="margin-bototm10" style="text-align:center;">Outras Categorias</h2>';
                $result = $mysql->sql_query("select * from TB_CATEGORIA inner join TB_GALERIA on TB_CATEGORIA.PK_CATEGORIA = TB_GALERIA.CATEGORIA where TB_CATEGORIA.DELETED IS NULL AND TB_CATEGORIA.CODUSUARIO=1 AND TIPO='1'");

                while ($row = mysql_fetch_assoc($result)) {
                    echo "<li class='isotope-item col-sm-6 col-md-3' style='list-style-type:none;'>";
                    echo "<div class='item-box'>";
                    echo "<figure>";
                    echo "<a title='".$row['DESCRICAO']."' class='item-hover' href='galerias.php?categoria=".$row['PK_CATEGORIA']."'>";
                    echo " <span class='overlay color2'></span>";
                    echo " <span class='inner'>";
                    echo " <span class='block fa fsize30 fa-picture-o'></span>";
                    echo "<strong>Ver</strong> Galeria                        </span>";
                    echo "</a>";
                    echo "<img class='img-responsive' src='../images/".$row['IMAGEM']."' width='260' height='260' style='max-height: 170px;' />";
                    echo "</figure>";
                    echo "<div class='item-box-desc'>";
                    echo " <small class='item-box-date'> </small>";
                    echo "<small style='display: inline;'>".$row['NOME']."</small>";
                    echo " <div class='row' style='max-width: 250px;'>";
                    echo " <div class='col-md-12'>";
                    echo "   <p class='similar-h4' style='display: inline;'>".$row['NOME']."</p>";
                    echo " </div>";
                    echo "</div>";
                    echo " </div>";
                    echo "</div>";
                    echo "</li>";

The other is as follows, in the code is to display only images / categories where the DELETED table value is NULL, I changed this to test, but the original idea is to display it when the table is empty and not null. For security reasons, what is deleted only receives the * tag in the DELETED table and only after a few days is actually excluded. I tried DELETED = '', but it did not work at all.

What am I doing wrong?

    
asked by anonymous 07.02.2017 / 13:15

1 answer

1

First thing gives an order by in your query:

select * from TB_CATEGORIA 
inner join TB_GALERIA on TB_CATEGORIA.PK_CATEGORIA = TB_GALERIA.CATEGORIA 
where 
   (TB_CATEGORIA.DELETED IS NULL OR TRIM(TB_CATEGORIA.DELETED) <> '')  
   AND TB_CATEGORIA.CODUSUARIO=1 
   AND TIPO='1'
Order by
    TB_CATEGORIA.PK_CATEGORIA

What is happening is that in your query the results will come like this:

  • Figure Category

    1        x
    1        y
    3        qq
    4        xx
    

You will have to make a control when you print the category:

if($row['PK_CATEGORIA'] != $categoria){
  //imprime thumb da categria
  $categoria = $row['PK_CATEGORIA'];
}
    
08.02.2017 / 01:43