I am having difficulties with a 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 \ trabalhowebGustavo \ user \ BancoEndereco.php on line 54
Here is 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 reporting the error - (54)
, is the while
line.
Any questions or additional information needed regarding the question, I am available.