I have a SQL query that I have already tested and it is bringing the correct result, my difficulty is in creating an array with the row data, transforming it into JSON and printing to the screen.
When I try with an array of strings, it works, when I try with an array of variables containing strings, it goes wrong ...
require '../conn/conn.php';
$conn = new Conn();
$conecta = $conn->conecta();
//essa consulta está retornando resultados, eu já testei
$sql = "SELECT u.id_user, u.nome, u.cargo, u.setor, u.usuario, p.nome
FROM usuarios as u
INNER JOIN permissoes as p ON (u.permissao = p.id_permissao)";
$result = mysqli_query($conecta, $sql);
$encode = null;
if (mysqli_num_rows($result)>0){
while($row = mysqli_fetch_array($result)){
//dessa forma não está dando certo
$encode[] = array( $row[1], $row[2], $row[3], $row[4]);
//quando eu tento da forma abaixo dá certo e imprime o json numa boa
// $encode[] = array("palavra1", "palavra2", "palavra3");
}
$conecta->close();
echo json_encode($encode);
}else{
echo "consulta vazia";
}
String array example (works)
$encode[] = array("palavra1", "palavra2", "palavra3");
Array example with variables (not working)
$encode[] = array($row[1], $row[2], $row[3], $row[4]);