0
Hello,
I am using the following code to return regions:
$query = 'SELECT * FROM Regiao';
$json = array();
$result = mysqli_query ($conn, $query);
while($row = mysqli_fetch_array ($result))
{
$regiao = array(
'id' => $row['Id'],
'nome' => $row['Nome'],
);
array_push($json, $regiao);
}
$jsonstring = json_encode($json);
echo $jsonstring;
die();
The result is as follows:
[
{
"id": "1",
"nome": "Norte"
},
{
"id": "2",
"nome": "Nordeste"
},
{
"id": "3",
"nome": "Sudeste"
},
{
"id": "4",
"nome": "Sul"
},
{
"id": "5",
"nome": "Centro-Oeste"
}
]
I am using the same code but in another file with the different select:
$query = 'SELECT * FROM Estado';
$json = array();
$result = mysqli_query ($conn, $query);
while($row = mysqli_fetch_array ($result))
{
$regiao = array(
'id' => $row['Id'],
'codigouf' => $row['CodigoUf'],
'nome' => $row['Nome'],
'uf' => $row['Uf'],
'regiao' => $row['Regiao'],
);
array_push($json, $regiao);
}
$jsonstring = json_encode($json);
echo $jsonstring;
die();
And the result in the second code is in White, does not return me absolutely anything. Could someone please help me? Thank you
I noticed that you are using uppercase letters in both table names and column names. You have checked whether the writing is correct?
– Phelipe
Hi Phelipe, I just checked your question and yes, both table name and column names are correct.
– Lucas Gomes
Check here carefully and really the code is exactly the same. The only possibility I’m seeing is actually the name of the table fields. Let’s see if anyone else can find some other mistake I didn’t see.
– Phelipe
If you run this query directly in the database, what is the result?
– Woss
The only difference between the tables is the number of columns, one has 2 the other has 5, and the number of rows, one has 5 and the other 27. But really the table name and columns are correct. Thank you very much, I will wait if someone can help me =)
– Lucas Gomes
Running this code directly in the database is returned to me the 27 results:
– Lucas Gomes
Showing 0 - 24 records (27 total, query took 0.0003 seconds.)
– Lucas Gomes