You don’t need to know this inside the loop to get that result, just remember that everything you perform before the loop will always be before the first line, just like what runs after it will be after the last line. So just do it:
echo 'Antes da primeira linha';
while ($dados = mysqli_fetch_assoc($query)){
echo $dados['nome'];
}
echo 'Depois da última linha';
This maintains the readability of the code and avoids having to evaluate two logical expressions at each loop. If you want to prevent messages from appearing when there are no records, just place this code snippet inside a if
on such condition.
What should happen if the first and last lines are the same, ie when there is only one record?
– Juven_v