1
I created this function, but, it returns only the first record of the table.
function pega_conteudo_pela_id($id_assunto){
global $conexao;
$query3 = "SELECT * FROM `{$id_assunto}`";
$result3 = mysqli_query($conexao,$query3) or die("MySQL error: " . mysqli_error($conexao) . "<hr>\nQuery: $query3");
while ($leiDB = mysqli_fetch_array($result3)) {
return utf8_encode($leiDB['conteudo']. "<br/>");
}
}
But if I put it on the links page, it works and takes all the records
case 'codigo-civil':
$query3 = "SELECT * FROM `codigo-civil`";
$result3 = mysqli_query($conexao,$query3);
while ($leiDB = mysqli_fetch_array($result3)) {
echo utf8_encode($leiDB['conteudo']. "<br/>");
}
break;
That’s right, I switched to
echo
and it worked, didn’t know it, thereturn
back only one result. Thanks!!!– Alê Moraes
@I made an Dit in case you really want to use the
return
of function.– Sergio
thanks, there is some difference between using the
echo
and thereturn
, besides thereturn
stop execution in the first loop?– Alê Moraes
@Allergy has to do with data flow and how you want to use the function return. It is practical to use function return along the line that called the function for code organization reasons. If you call a function that is in another file and the function does HTML echo it can be difficult to know what the code is doing. But basically there’s no effect on the code other than the
return
interrupt the function.– Sergio