1
Hello!
Good Morning, Good Afternoon or Good Night!
I have a little problem for a while and I just realized now (after about 10 pages of this type), I have a page that lists all the data of the table on boards (listarplacas.php) and in it is printed all the results according to the command "SELECT * FROM STOCK, my problem is that as the printed table has 'titles' (TYPE, TRANSACTION, SIZE, QUANTITY) the first result is always hidden by the titles, as I can to display the results of the query from the second line?
Images that help describe the problem:
DATABASE QUERY USING THE ABOVE COMMAND
DATABASE QUERY WITH THE SAME COMMAND ABOVE BUT PRINTED WITH PHP/CSS/HTML
If you notice the first result "gets eaten" by the titles (TYPE, TRANSACTION, SIZE, QUANTITY) of the table, sometimes it’s a stupid mistake I’m not noticing, if you can help me!!
PAGE CODE: list
<CDOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ESTOQUE DE PLACAS</title>
<link rel="stylesheet" type="text/css" href="estilo/estilo.css">
</head>
<body>
<?php
include "config/cabecalho.php";
?>
<div class="container">
<div class="titulo-principal">ESTOQUE DE PLACAS</div>
<button value="VOLTAR" class="botao" onClick="history.go(-1)"><img src="imagens/iconevoltar.png" class="img-botao"> VOLTAR</button>
<button value="ATUALIZAR" class="botao" onClick="history.go(0)"><img src="imagens/iconeatl.png" class="img-botao"> ATUALIZAR</button>
<br>
<br>
<hr>
<br>
<?php
include "config/conectar.php";
$sql = "SELECT * FROM ESTOQUECVISUAL";
$resultado = mysqli_query($conexao,$sql);
if(mysqli_num_rows($resultado)>0){
$linha = mysqli_fetch_assoc($resultado);
//TABELA ESTOQUECVISUAL (PLACAS - comunicação visual)
$id = $linha["ID"];
$tipo = $linha["TIPO"];
$transacao = $linha["TRANSACAO"];
$tamanho = $linha["TAMANHO"];
$quantidade = $linha["QUANTIDADE"];
}
?>
<table border="1" style="border-collapse: collapse" width="60%">
<tr class="cabecalho-tabela">
<td width="20%">TIPO</td>
<td>TRANSAÇÃO</td>
<td>TAMANHO</td>
<td>QUANTIDADE</td>
<td width='2%'></td>
</tr>
<?php
while($linha = mysqli_fetch_assoc($resultado)){
$tipo = $linha['TIPO'];
$transacao = $linha['TRANSACAO'];
$tamanho = $linha['TAMANHO'];
$quantidade = $linha['QUANTIDADE'];
echo"
<tr>
<td>$tipo</td>
<td>$transacao</td>
<td>$tamanho</td>
<td>$quantidade</td>
<td><a href='alterarestoqueplacas.php?id=$id'><img src='imagens/iconeditar.png' /></a></td>
</tr>
";
}
?>
</table>
<br>
<hr>
<br>
<br>
<?php
include "config/rodape.php";
?>
</div>
</body>
</html>
If I miss something I add later, I am layman in the subject...
Your code is wrong is using mysqli_fetch_assoc twice only the second is required inside your While. In the first call it returns the first result line for the variables defined, in the second call it starts from the second result onwards. There is no need to load the result of your query into the variables if you do not use. This if instruction block(mysqli_num_rows($result)>0) is completely unnecessary.
– Rafael Salomão
Wow, thank you so much!! That was just it!!!
– Julio Sanchez
You’re welcome Brother! I was going to post a full reply but I was afraid to confuse you. What happens is that mysqli_fetch_assoc will open a handler of the result obtained in your query, internally there is a counter variable that increments how many records were read, as called twice, this internal variable of the function had already been incremented the first time. That’s why the second time he called mysqli_fetch_assoc, he started from the second record obtained.
– Rafael Salomão