0
I have an object inside another object. How do I catch this second object? Follow picture:
$scope.calcular = function(valor){
valor.receitaMediaMensal = $scope.receitaMediaMensal;
valor.idempresa = $rootScope.idempresa;
valor.valorTotalCustoIndireto = $scope.ValorTotalCustoIndireto;
valor.valorTotalCustoDireto = $scope.ValorTotalCustoDireto;
valor.valorTotalDespesasVariaveis = $scope.ValorTotalDespesasVariaveis;
valor.custoIndireto = $scope.custoIndireto;
console.log(valor);
$http.post(url_mcp, valor).success(function(data){
console.log(data);
})
};
php:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
include_once("../con.php");
$pdo = conectar();
$data = file_get_contents("php://input");
$data = json_decode($data);
print_r($data);
$valorPrecoVenda = $data->valorPrecoVenda;
$receitaMediaMensal = $data->receitaMediaMensal;
@$descontoPromo = $data->descPromo;
@$descontoFinan = $data->descFinan;
$valorTotalCustoDireto = $data->valorTotalCustoDireto;
?>
If possible post your code. It gets easier. You also used the tag PHP, but posted an image with output of Javascript ?!
– Valdeir Psr
I’m sending by JS, angled and picking by php. What I sent is how JS is sending to php
– GustavoSevero
Code posted @Valdeirpsr
– GustavoSevero
Which object do you want to handle? the account?
– rray
No, value... I just need the value.
– GustavoSevero
I’m using a for take-by-position, but I’m not getting: $Qtd = Count($costIndirect); $pos = 0; for($i=0; $i <= $Qtd; $i++){ $pos = $costIndirect[$i]->value; echo $pos." n"; }
– GustavoSevero
echo $data->custoIndireto[0]->valor;
You can usereset
to take the first index of the array orend
to catch the last. Or still afor
orforeach
.– Valdeir Psr
Thanks for the @Valdeirpsr tip, but how can I take this data inside a for, because I will have more of a value to take, you understand?
– GustavoSevero
@GustavoSevero https://hastebin.com/inugokerec.xml
– Valdeir Psr
It’s @Valdeirpsr, I tried it with for, but it’s a mistake: "<b>Notice</b>: Undefined offset: 2 in <b>/Applications/MAMP/htdocs/systems/webApps/fluxo_de_box/fluxojoin_2.0/php/pricing/matrizCalculoPrecificacao.php</b> on line <b>45</b><br /> <br /> <b>Notice</b>: Trying to get Property of non-Object in <b>/Applications/MAMP/htdocs/systems/webApps/fluxo_de_box/fluxojoin_2.0/php/pricing/matrizCalculoPrecificacao.php</b> on line 45" This line 45 is: echo $data->costIndirect[$i]->value, PHP_EOL;
– GustavoSevero
Another thing, I need to put a different variable those values, so I tried it. With foreach there is no error, but I cannot separate the values into different variables.
– GustavoSevero
@Gustavosevero fix the error and modified example #2. I added an example of how to create and capture variables with dynamic names. https://hastebin.com/aqohokayoj.xml
– Valdeir Psr
All right, thanks...
– GustavoSevero