I have a problem to find out how to put a Json in a cycle to read all the data of the array and generate variables with JS.
In this way I create the Json arrangement
function info(){
global $conn;
//Query a seleccionar en la base de datos
$query = "SELECT permisos.idTipoMeta, tiposmetas.nombreMeta, permisos.hab FROM 'permisos'
INNER JOIN tiposmetas ON permisos.idTipoMeta = tiposmetas.idTipoMeta
WHERE idUsuario = " . $_GET['idUsuario'];
//Se ejecuta el query y si no se puede pasar a $result, hubo un problema con el query
if(!$result = $conn->query($query)){
die('Ha ocurrido un error ejecutando la solicitud. Error: [' . $conn->error . ']');
}
$output = array();
while($tRow = $result->fetch_assoc()){
$row = array();
$keys = array_keys($tRow);
for ($i = 0; $i<count($tRow); $i++){
// if($keys[$i] != "SuspendidoProv" ){ //agregar todas las columnas excepto "SuspendidoProv" que se agregará en un input
$row[] = $tRow[$keys[$i]];
// }
}
$output['aaData'][] = $row;
}
//Imprime la salida como un arreglo codificado en JSON
echo json_encode($output);
$conn->close();
}
I tried to call it in the following way to put it inside a cycle for
:
for (var i = 0; i < output.length; i++) {
output[i]
}
But it turns out that the variable is not defined. Then I checked the chrome console to know what name it is getting and it appears:
{aaData: [["1", "FACTURADO", "0"], ["2", "COBRANZA", "1"], ["3", "PROSPECTOS POTENCIALES", "1"],…]
Which means that the data is being sent, but with the name aaData
but still changing by this name I can not figure out how to read this data with Javascript.
I add the code with which I link the php file with js through AJAX
$.ajax({
dataType: "json",
url : 'usuarios-get.php?act='+ act +'&idUsuario='+ idUsuario,
success: function(response){
The PHP file is usuarios-get.php
.