3
I’m having difficulties with an SQL query in PHP, when I make a query I get the following error:
Warning: mysqli_fetch_assoc() expects Parameter 1 to be mysqli_result, Boolean Given in C: xampp htdocs trabowebGustavo usuario Bancoendereco.php on line 54
It follows the code below the function that returns the error:
function listaEnderecos($conexao, $filtro, $ordem, $usuario) {
$enderecos = array();
$sql = "select enderecos.*, us.email, cidades.nomecidade
from enderecos
inner join usuarios us on enderecos.idusuario = us.id
inner join cidades on cidades.id = enderecos.idcidade
where us.email = {$usuario}";
if ($filtro <> "") {
$sql = $sql .
" where enderecos.idcidade like '%{$filtro}%'";
}
if ($ordem <> "") {
$sql = $sql .
" order by {$ordem}";
}
$resultado = mysqli_query($conexao, $sql );
while ($endereco = mysqli_fetch_assoc($resultado)) {
array_push($enderecos, $endereco);
}
return $enderecos;
}
The line that reports the error - (54)
, is the line of while
.
Any doubt or additional information required in relation to the question, I am available.
If the answer solved the problem, mark it as accepted. See How and why to accept an answer?
– rray