0
I get a string in format:
[name, Qtd, price, name, Qtd, price...].
Ex: [Tomato Sauce, 12, 4.59, Popcorn, 5, 7.90...]
I want to separate every 3 commas an element and separate each element into 3 more subelements.
Ex: $pedido[i] = $subelemento_nome, $subelemento_qtd, $subelemento_preco;
$subelemento_nome[i];
$subelemento_qtd[i];
$subelemento_preco[i];
And for each element to return something like this:
$pedido[i] = "<p>".$subelemento_qtd[i]."x ". $subelemento_nome[i]." - R$ ".$subelemento_preco[i]."</p><br>";
Return:
<p>12x Molho de Tomate - R$ 4.59</p><br>
<p>5x Pipoca - 7.90</p><br>...
At the end of everything I will send the string $request to my database.
Very good, exactly as I wanted. You know tell me pq echo shows the output as expected but when I pass to my database only the last item is saved?
– Joao Victor Menom
Your example, for example, saves to db only
<p>5x Pipoca - R$ 7,90</p>
– Joao Victor Menom
Why you must have done wrong :D hehehe Maybe you are storing in variables and only saving in the bank outside the loop repetition, then you will save only the current values of the variables (but it is only speculation).
– Woss
I get it... how do I store all the results in a variable to be recorded at once? If I put the mysql part in the loop, each value is saved individually.
– Joao Victor Menom
I got :D, did some research and found the solution. I added
$pedido_conteudo = "<p>{$qtd}x {$nome} - R$ {$preco}</p>\n";
and$conteudo .=$pedido_conteudo;
inside the loop, and outside the loop is the mysql part saving $content– Joao Victor Menom