I do not know why, but it shows me the data correctly in one query and in the other I get the data Undefined
!
Showing the following error when going through the for console.log($scope.servicio):
Notice : Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/Paneldetencion/app/php/consultaServicios.php on line 9
Error querying database.
And when I show only the data console.log(data):
Notice : Undefined property: stdClass :: $ service_id in /Applications/XAMPP/xamppfiles/htdocs/Paneldetencion/app/php/consultaServicios.php on line 9
Error querying database.
The two throw me to the same line the 9: $postdata = file_get_contents("php://input");
The php query is this:
<?php
header('Access-Control-Allow-Origin: *');
date_default_timezone_set("Chile/Continental");
$db = mysqli_connect('localhost','root','','mongos')
or die('Error connecting to MySQL server.');
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$id = $request->id;
$query = "SELECT identificador, nombre FROM Servicios WHERE id =".$id;
mysqli_query($db, $query) or die('Error querying database.', error_reporting());
$result = mysqli_query($db, $query);
$array = array();
while ($row = mysqli_fetch_array($result)) {
$array[] = array(
$row["identificador"]
$row["nombre"]
);
}
echo $json_info = json_encode($arr);
?>
And the controller is like this:
$http({
method: 'POST',
url: 'http://localhost/Paneldetencion/app/php/consultaServicios.php',
// url: 'php/consultaServicios.php',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
data:{
id: 38
}
})
.then(function(data) {
var dat = data.data;
$scope.servicio = [];
for (var i = 0; i < dat.length; i++) {
var datos = {
nombre: dat[i].nombre,
identificador: dat[i].identificador,
};
$scope.servicio.push(datos);
}
console.log("RESPUESTA: ",$scope.servicio)
});
As I said before, this same query I have it with other data and returns them correctly, but not all the data by the id
where. But he shows them. Here all data is Undefined