0
Good afternoon guys, I read the whole forum and tried several things, but I can’t extract the data from the array to manipulate.
Well, I’m putting together a system where, after making a sale, it saves the sale on a table with the seller’s name and the total sale.
I was able to extract this data and save.
The other part is to take the sale products and save in another table and associate the sale id above in the products.
My Array comes like this:
array(3) {
["vendafinal"]=>
array(2) {
[0]=>
array(3) {
["vendaproduto"]=>
string(10) "Produto 02"
["vendaqtd"]=>
string(2) "10"
["vendavalor"]=>
string(1) "5"
}
[1]=>
array(3) {
["vendaproduto"]=>
string(10) "Produto 01"
["vendaqtd"]=>
string(1) "5"
["vendavalor"]=>
string(2) "10"
}
}
["vendedor"]=>
string(4) "Erik"
["totalvenda"]=>
string(3) "100"
}
The Seller and the sale total I managed to pull with:
$vendedor = $_POST['vendedor'];
$totalvenda = $_POST['totalvenda'];
$data = date("Y-m-d");
$hora = date("H:i:s");
Saved at the bank and he displays perfectly. The other part is to save the products in another table, with the quantity and value of the product and also the id of the previous sale. But ta bone, I could not work these objects nor stick. I tried foreach, for and nothing.
I send the data to this PHP page via AJAX:
function insereVenda() {
var vendafinal = [];
var linhas = $("tbody>tr");
var vendedor = $("#vendedor").val();
var totalvenda = $("#totalvendas").text();
linhas.each(function () {
var produto = $(this).find("td:nth-child(1)").text();
var quantidade = $(this).find("td:nth-child(2)").text();
var valor = $(this).find("td:nth-child(3)").text();
var sale = {
vendaproduto: produto,
vendaqtd: quantidade,
vendavalor: valor
};
vendafinal.push(sale);
});
var dados = {
vendafinal: vendafinal,
vendedor: vendedor,
totalvenda: totalvenda
};
$.post("salvarvendabkp.php", dados, function (retorna) {
$("#retorna1").html(retorna);
});
}
Please clarify your problem or provide additional details in order to highlight exactly what you need. The way it’s written these days it’s hard to tell exactly what you’re asking.
–