<?php
include 'conexion.php';
$consulta = mysqli_query ($conn, "SELECT * FROM Usuario");
// error mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in ----->
// se arreglo viendo el error asi 'if (!$consulta){ echo mysqli_error ($conn);}' resulta que escribi mal la tabla, usarlo para ver mas errores
// https://www.w3schools.com/php/func_mysqli_query.asp
// mysqli_query(connection,query,resultmode);
// https://www.w3schools.com/sql/
if (mysqli_num_rows ($consulta)> 0)
// mysqli_num_rows ($consulta) va a ser igual al numero de columnas, de la misma manera que "Mysqli_query ($conn, "SELECT * FROM Usuarios")" sera igual al valor que lleva dentro del parentesis. Por lo que si es mayor a 0, osea si hay columnas en la consulta, viendo asi que fue satisfactoria, se hace lo siguiente.
//array es fila (<-- -->), no columna
{
echo "<p>";
// mysqli_fetch_array(result,resulttype);
// [result ]= Mysqli_query(), mysqli_store_result() or mysqli_use_result()
// [resulttype ] = MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH
while ($row = mysqli_fetch_array($consulta, MYSQLI_ASSOC) )
// otro error: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC'
// use esto "if (!$row){ echo mysqli_error ($MYSQLI_ASSOC);}" resulta que coloque MYSQL_ASOC, cuando tuvo que ser MYSQLI_ASSOC
// https://www.phpclasses.org/discuss/package/9199/thread/4/
{
echo "<tr>";
echo "< <td>".$row['nombre']."</td>";
echo "< <td>".$row['fecha_creacion']."</td>";
echo "< <td>".$row['nick']."</td>";
echo "</tr>";
echo "
<table>
<thead>
<tr>
<th>Nombre</th>
<th>Fecha creacion</th>
<th>Nick</th>
</thead>
</table>
";
}
}
?>
I still can not get a clear idea of what 'mysqli_fetch_array' does, I still do not have a mental image about it, and that is that when I run the code in the browser I get this:
< Jenny < 2018-08-16 < Wick Name Date creation Nick < danphan < 2018-08-16 < danphan29 Name Date creation Nick < mmtuts < 2018-08-16 < hood Name Creation date Nick
Each time I add a new user I update the browser and each one comes out with "Name Creation Date Nick" below, I do not know why, when I only wrote it once, that you are allowing this format to appear on the whole list.
As for the format of the Mysqli_fetch_array, in the second parameter, 'resulttype' I do not see what is the difference between 'MYSQLI_ASSOC, MYSQLI_NUM, MYSQLI_BOTH' or what advantages it has from each other, I did not find much about it. Thanks.