Popular array on online server

Asked

Viewed 49 times

0

I’m a beginner in programming and I’m developing an android application that uses PHP and requests with Mysql. I initially tested all the features on the local server to then migrate it to an online server, in this case, Hostinger.

One of my PHP files returns the value of an array correctly on the local server, but when using the same PHP file on the online server with the same database, the array only responds as TRUE when running echo.

I tested by echo each line and it is working perfectly, just not being able to associate the values to Keys.

$resultado = array();
$ordenado = mysqli_query($connect, $ordenarExercicio);  

while ($pacientes = $ordenado->fetch_assoc()){  
    echo $pacientes['grupo'];              //imprime OK
    echo $pacientes['nome_exercicio'];     //imprime OK
    echo $pacientes['utilizar_exercicio']; //imprime OK

    $resultado[] = array("grupo" => $pacientes['grupo'],    
                         "nome" => $pacientes['nome_exercicio'],
                         "habilitar" => $pacientes['utilizar_exercicio']
                        ); 

}

echo json_encode($resultado);  //imprime TRUE
  • It is the paid version. I have access to the bank by phpmyadmin. In this same file there are 2 other queries that work perfectly. The data is being passed correctly, only the array that is returning wrong.

2 answers

0

Look, I do not understand well of Arrays in PHP, but from what I understand by basis the variable $result need not have square brackets before inserting the value, since it will already make it an ARRAY.

$resultado = array("grupo" => $pacientes['grupo'],    
                     "nome" => $pacientes['nome_exercicio'],
                     "habilitar" => $pacientes['utilizar_exercicio']
               );

0

Try using the print_r function ($results) to see the output of the array being sent.

And try to take out the [] of the $result variable[].

Browser other questions tagged

You are not signed in. Login or sign up in order to post.