1
I have 3 tables do the Inner Join in them , but I need to return a json, I only managed to return a simple select:
My Sql clause:
SELECT publicacao.codPublicacao as codpublicacao,
usuario.nome as nomeusuario,
publicacao.categoria as categoria,
publicacao.endereco as endereco,
publicacao.tipo as tipo,
publicacao.descricao as descricao,
cidade.nome as nomecidade, publicacao.contato as contato
FROM `publicacao`
inner join usuario on publicacao.codUsuario = usuario.codUsuario
inner join cidade on publicacao.codcidade = cidade.codcidade
Php:
$sql = "SELECT publicacao.codPublicacao as codpublicacao,usuario.nome as
nomeusuario, publicacao.categoria as categoria,
publicacao.endereco as endereco, publicacao.tipo as tipo,
publicacao.descricao as descricao, cidade.nome as nomecidade,
publicacao.contato as contato FROM `publicacao` inner join usuario on
publicacao.codUsuario = usuario.codUsuario inner join cidade on
publicacao.codcidade = cidade.codcidade";
$result = $conn->query($sql);
$encode = array();
while ($row = $result->fetch_assoc()) {
$encode[] = json_encode($row);
}
echo json_encode($encode);
?>
This tried is API, search on json_encode http://php.net/manual/en/function.json-encode.php and there is another easy way to use GO program
– KingRider
Why don’t you use
json_encode();
results (lines) returned from BD?– Miguel
I used json_encode($vector) (I do not know if it is correct) but it does not return anything, the page is empty, but when I use a simple select, it appears json
– Diego Noceli
You can provide the table structure together with data in an SQL file for testing?
– Vinicios Yals
Diego, it’s all right echo? Do not use while json_encode and for later,
$encode = $row
andecho json_encode($encode)
to exit the screen result.– KingRider
The database is here ->https://drive.google.com/open?id=0B-aEUv85JPz2ZzdiZFAtTnJYN2M
– Diego Noceli