0
I have the following code
$result_categorias = "SELECT * FROM categorias ORDER BY ordem ASC";
$resultado_categorias = mysqli_query($conn, $result_categorias);
$total_categorias = mysqli_num_rows($resultado_categorias);
$quantidade_pg = 3;
<div class="row">
<?php while($row_categorias = mysqli_fetch_assoc($resultado_categorias)){?>
<div class="col-md-6">
<article class="mr-categorias-single">
<div class="mr-categorias-img">
<img src="imagens/categorias/<?php echo $row_categorias['imagem']; ?>" width="360" alt="">
<div class="mr-categorias-single-content">
<a href="produtos.php?&id=<?php echo $row_categorias['id']; ?>">
<h3><?php echo $row_categorias["nome"]; ?></h3>
<span><?php echo $row_categorias["resumo"]; ?></span>
</a>
</div>
</div>
</article>
</div>
<?php } ?>
</div>
Pull the categories and display through while, a total of 3 results according to the $quantidade_pg=3;
The beginning of the while I have a <div class="col-md-6">
which is in the 33% width css file to split the total into 3 columns.
But if somehow only have 2 categories on the page, would like the width automatically changes to 50% if it has only 1 category displayed in 100%.
Is there any way to make php when giving the width result according to the number of categories displayed in the while result?
you want to modify the class for the
col-md-*
or you want to set thewidth
ofdiv
?– mercador
it is better you make your layout adapt to the content in some way than use backend to manipulate layout. golden tip.
– Leandro
Thanks @Leandro - Good tip.
– Marcelo Rossi