2
I have an SQL query that I have already tested and it is bringing the correct result, my difficulty is in creating an array with the line data, turn it into JSON and print on 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";
}
Example array with strings (works)
$encode[] = array("palavra1", "palavra2", "palavra3");
Example array with variables (does not work)
$encode[] = array($row[1], $row[2], $row[3], $row[4]);
$Ncode[] = $Row;
– Fábio
Add an example of
array de strings
andarray de variáveis
– Edson Horacio Junior
@Edsonhoraciojunior are these: array with variables
$encode[] = array( $row[1], $row[2], $row[3], $row[4]);
and now with strings$encode[] = array("palavra1", "palavra2", "palavra3");
. The second works the first no.– Victor Araujo
@Victoraraujo this type of information should be on the question because it can help other users, can let me edit here.
– Edson Horacio Junior
What is the value of
$row[1]
?– Edson Horacio Junior
@Edsonhoraciojunior the first $Row[1] is "Administrator", the second is "Health Test", which is in agreement with the bank
– Victor Araujo