0
how can I go through all the elements of a php vector in javascript because my javascript only takes the last name but my 'var_dump()' is receiving all how can I do this someone can help me?
php code:
foreach($_SESSION['carrinho'] as $id => $qtd){
$sql = "SELECT * FROM produtos WHERE id_produto= '$id'";
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);
$nomes = $ln['nome'];
$preco = $ln['preco'];
$sub = $ln['preco'] * $qtd;
$img = $ln['img'];
$desc = $ln['descricao'];
$id = $ln['id_produto'];
$nomes = array($nomes);
$nomes = implode("|", $nomes);
var_dump($nomes);
}
javascript code:
var i, array_produtos, string_array;
//recebe a string com elementos separados, vindos do PHP
string_array = "<?php echo $nomes; ?>";
//transforma esta string em um array próprio do Javascript
array_produtos = string_array.split("|");
//varre o array só pra mostrar que tá tudo ok
for (i in array_produtos)
alert(array_produtos[i]);
intendi thank you very much
– Leonardo Costa
this way that Voce explained there is no way to do type for him to get the quantity of product type the product 1 has 2 quantity and the product 2 has 3 quantities. That way it will print like this: product1 | product 2 2 | 3 wouldn’t have as I print respectively? ex: product 1 quantity 2 | product 2 quantity 3 ?
– Leonardo Costa
Then the correct thing would be for you to make use of json, and convert it to a javascript object
– Hiago Souza
I’ll edit the answer.
– Hiago Souza
Ready the answer is adapted
– Hiago Souza
in Alert the quantity enters as Undefined type has no problem because I will send to email by ajax?
– Leonardo Costa
the quantity was not in the vector... I already arranged again the answer
– Hiago Souza
or give a +1 ai in the answer now it is more complete
– Hiago Souza
Of course I’ll give you +1
– Leonardo Costa
worked the amount?
– Hiago Souza
ran agr am trying to send the data via ajax
– Leonardo Costa
Do you know how I feel when I click to finalize the purchase he send me an email and at the same time call the form of the pagseguro passing the total amount of the purchase I can not do because of the action of pagseguro you have any idea? type so I’ll just send the total amount to the pagseguro and this example you answered to get all the data I will pass by email
– Leonardo Costa
So @Leonardocosta this would be another question, but look for PHP Mailer and the use of AJAX.
– Hiago Souza
type guy I know how to do this I already use php for a long time Mailer and ajax tbm I have several things using the 2 but d good face vlw by Resp ai
– Leonardo Costa
need only ask ;)
– Hiago Souza
Since Javascript was used, it would be good to keep the languages separate from each other, based on how they operate.
– Edilson