Help for while php

1

I am needing help to do a while or for or a correct way to repeat content

<?php 
mysqli_select_db($conexion, $database_conexion);
$query_DatosCategorias = sprintf("SELECT * FROM categorias WHERE estado>0");
$DatosCategorias= mysqli_query($conexion, $query_DatosCategorias) or die(mysqli_error());
$row_DatosCategorias = mysqli_fetch_assoc($DatosCategorias);
$totalRows_DatosCategorias = mysqli_num_rows($DatosCategorias);

$total = $totalRows_DatosCategorias;
$limite = 8;
$listas = null;
$inicio = 1;
$k = null;
$listas = $total/$limite;
$cantidadListas = ceil($listas);
?>
<footer class="site-footer footer-light" style="background-image: url(<?php echo $urlWeb;?>/img/footer-bg-alt.png);">
<div class="container">
<div class="row">
<div class="col-lg-6">
<!-- categorias-->
<section class="widget widget-links">
<h3 class="widget-title">Categorias</h3>
<div class="row">
<?php
for ($i=$inicio; $i <=$cantidadListas; $i++) { 
echo "<div class='col-md-6'>";
for ($j=1; $j <=$limite && $k<$total; $j++) { 
$k = $k+1;

//aca nesesito hacer un bucle for o while pero no me da resultado
echo "<ul>";
 echo '<li>'.$row_DatosCategorias['id'].'</li>';
echo "</ul>";
}
echo "</div>";
}
?>
    
asked by Matias 30.06.2018 в 15:10
source

1 answer

1

Instead of the for , put a while to go through the result. I have taken the ul tag out because I have assumed that the results are the items in the list. Modified so that several lists come out.

$i=0;
while ($row_DatosCategorias = mysql_fetch_assoc($DatosCategorias)) {
  $i++;
  if ($i==1) {echo "<ul>";} // primera lista
  echo '<li>'.$row_DatosCategorias['id'].'</li>';
  if ($i % $limite == 0 || $i == $total) { 
    echo "</ul>"; // cerrar lista
    // Si quedan más elementos abrir otra
    if ($i < $total) {echo "<ul>";}
  }
}
    
answered by 30.06.2018 / 15:22
source