2
I made a query with a Join to get information from the database, I tested it in mysql and it worked perfectly, the problem is that it does not work in php, not from the error in the execution but the return is null, even if I change the variables for text from the database it does not work, I used var_dump() to check if there was a syntax error but it does not have.
$query="SELECT t1.* FROM tb_anuncio AS t1 JOIN tb_localizacao AS t2 ON t2.cd_localizacao = t1.cd_localizacao WHERE 1=1 AND t1.cd_categoria =".$categoria->getCd()." AND t2.nm_estado ='".$estado."' AND t2.nm_municipio ='".$municipio."' LIMIT ".$init.",".$max."";
$retorno = $this->conexao->query($query) or die(mysql_error());
while($anuncio = mysqli_fetch_assoc($retorno))
{
$anuncios[] = $anuncio;
}
var_dump:
"SELECT t1.* FROM tb_anuncio AS t1 JOIN tb_localizacao AS t2 ON t2.cd_localizacao = t1.cd_localizacao WHERE 1=1 AND t1.cd_categoria =1 AND t2.nm_estado ='AC' AND t2.nm_municipio ='Acrelândia' LIMIT 0,17"
In $query I can do in return tbm if you want, actually it is not a var_dump I put a break point in vscode and took the contents of the variable
– Reignomo
pq
WHERE 1=1
?– user60252
Just to help with the concatenation
– Reignomo
Returned
null
, then the problem is in the query.– Jorge.M
@LeoCaracciolo https://answall.com/questions/12525/70
– Bacco
@Bacco, congratulations, very well explained! Why didn’t I think about it? rs
– user60252