How to get all rows of mysqli_fetch_array from a query?

0

I have the following code, with which I can only get the first row, the purpose is to get each row and display it in a single table

<?php
 include("conexion.php");  




$sql="SELECT * FROM libros  ";
$res=mysqli_query($conexion,$sql);


$fieldinfo=mysqli_fetch_field_direct ($res,1);




$arreglo = array();


while($row=mysqli_fetch_array($res)){

$arreglo[] = $row;

shuffle($arreglo);
}

foreach ($arreglo as $rows){


    <?php
         include("conexion.php");  

        $sql="SELECT * FROM catalogos  ";
        $res=mysqli_query($conexion,$sql);


        $dato1= $row[1];

        $dato2=$rows[2];

        $dato3=$rows[3];

        $dato4=$rows[4];

            }



   ?>

And this code must fill in the tables

    <p>
    <table width="657" height="71" border="1">
  <tr>
    <td><? echo"$dato1";?>
    <p><? echo "$dato2";?></p>
    <p><? echo "$dato3";?></p>
    <p><? echo "$dato4";?></p>
    <p><? echo "$dato5";?></td>
    <td><? ?></td>
    <td><? ?></td>
    <td><? ?></td>
  </tr>
</table>

    <table width="657" height="71" border="1">
      <tr>
        <td><? ?></td>
        <td><? ?></td>
        <td><? ?></td>
        <td><? ?></td>
      </tr>
    </table>
    <table width="657" height="71" border="1">
      <tr>
        <td><? ?></td>
        <td><? ?></td>
        <td><? ?></td>
        <td><? ?></td>
      </tr>
    </table>

the output should be something like this image

    
asked by August C. 10.04.2017 в 05:17
source

1 answer

0

Next I assume that your PHP code is in the same one where you arm the HTML (table):

<html>
<!-- Tus metas y referencias a link JS. CSS.... -->
<body>
<?php
   // Proceso para obtener los datos que ya tienes (primer fragmento de código que muestras
   // Desde luego esto puede ir antes del body e incluso html
   foreach($arreglo as $row){
?>
<!-- ya que al parecer quieres un table por cada fila -->
<table width="657" height="71" border="1">
   <tr>
      <td><?= $row[1]; ?></td>
      <td><?= $row[2]; ?></td>
      <td><?= $row[3]; ?></td>
      <td><?= $row[4]; ?></td>
   </tr>
</table>
<?php
   }
?>
</body>
</html>
    
answered by 10.04.2017 в 05:50