php array for json will not all data

-2

Hello, I'm having a problem with my code and I wanted your help.

I need to get data from a table and send it as json, I have 10 items in my table but json just sends one.

Table: Location


InmycodewhereIputallPHPandMsqli

include("connect.php");

header("Content-Type: application/json");

$queryString =  "SELECT * FROM 'local'";   

$query = mysqli_query($conexao, $queryString) or die(mysqli_error());

$paises = array();

while ($pais = mysqli_fetch_assoc($query)) {

    $paises['paises'] = $pais['paises'];

}

echo json_encode($paises);

And it only returns me the last item that is the "argentina" and was the maximum that I got because I tried several ways. if you can help me there I thank you.

    
asked by anonymous 16.07.2017 / 06:44

2 answers

0

Return like this:

$paises = array();
//EDIÇÃO  while ($pais = mysqli_fetch_assoc($conn, $query)) {
while ($pais = mysqli_fetch_assoc($query)) {

    $paises[] = array(
        "paises" => $pais['paises'];
    );

}

echo json_encode($paises);

Because the way you are sending is only replacing the value.

    
16.07.2017 / 07:00
-1

Thanks to everyone, I've been able to solve the problem.

$paises = array();

while ($pais = mysqli_fetch_assoc($query)) {

$paises[] = $pais['paises'];

}

echo json_encode($paises);

And I changed the DB which was the main problem

    
17.07.2017 / 16:09