1
<?php
//database configuration
$dbHost = '127.0.0.1';
$dbUsername = 'root';
$dbPassword = '';
$dbName = 'master';
//connect with the database
$Mysqli = new mysqli($dbHost,$dbUsername,$dbPassword,$dbName);
$arr = array();
//get matched data from skills table
if(empty($erro)){
$query = "SELECT
r.endereco_cep AS CEP,
r.endereco_logradouro AS ENDERECO,
b.bairro_descricao AS BAIRRO,
c.cidade_codigo AS CODCID,
c.cidade_descricao AS CIDADE,
e.uf_sigla AS SIGLA,
e.uf_descricao AS ESTADO
FROM
cep_endereco AS r
LEFT JOIN cep_bairro AS b ON b.bairro_codigo = r.bairro_codigo
LEFT JOIN cep_cidade AS c ON c.cidade_codigo = b.cidade_codigo
LEFT JOIN cep_uf AS e ON e.uf_codigo = c.uf_codigo
WHERE
c.cidade_codigo = '3169'";
$result = $Mysqli->query($query);
if($result->num_rows > 0){
$obj = $result->fetch_object();
$arr['result'] = true;
$arr['dados']['endereco']= $obj->ENDERECO;
}else{
$arr['result'] = false;
$arr['msg'] = "USUARIO INCORRETO";
}
}else{
$arr['result'] = false;
$arr['msg'] = $erro;
}
echo json_encode($arr);
?>
In the above query the intention is to return all addresses in a json, but it is only returning the first one, as it could return all ?
Current return:
{"result":true,"dados":{"endereco":"RUA ABEL COUTO"}}
Only in php is not returning anything on the screen, but if I give a var_dump($result); it has the results, strange, ta missing something minimal
– Chefe Druida
If you access this php page in the browser it is empty?
– Jessika
yes, more if in php I include var_dump($result); it returns: array(1873) { [0]=> array(2) { ["result"]=> bool(true) ["data"]=> array(1) { ["address"]=> string(14) "STREET ABEL COUTO" } [1]=> array(2) { ["result"]=> bool(true) ["data"]=> array(1) { ["address"]=> string(15) "STREET OF ACACIAS" } } .....
– Chefe Druida
yes pq result is an array ai gets that way. Ai qnd vc uses the
echo json_encode($resultado);
it turns the array to json. But it was to show the json on the php page.– Jessika
Solved: I put json inside your while
– Chefe Druida
I supplemented your reply
– Chefe Druida