0
I have a div that is composed of some text fields, and a button that calls a js function that duplicates that div if the user clicks...
Example:
Code:
<div id="duplicar">
<!--.....aqui vai o html dos campos(nao coloquei pq está muito grande)-->
</div>
<div id="aqui"></div>
<!--botao que chama a função para duplicar a div-->
<div style="width:910px; float:left; margin-right:30px; margin-top:20px;">
<input type="button" value="+" onclick="mais()"; class="btn btn-outlined btn-success"/>
</div>
<script>
function mais() {
var destino = document.getElementById("aqui");
var novadiv = document.createElement("div");
var conteudo = document.getElementById("duplicar");
novadiv.innerHTML = conteudo.innerHTML;
destino.appendChild(novadiv);
}
</script>
Okay, now what I need:
When I give a Submit in my form, the values of the fields are passed via POST in array form:
item[]
Qtd[]
valorunit[]
So if the user duplicates the div 3x for example, the array holds the 3 inserted values...
Now how do I save this array to the database?
-I thought of putting everything together in a string, separating by ; (point and comma)...and saving in a column of the bank, this I managed to do using using:
//conta o tamanho do array passado via POST
$tam = sizeof($peca);
$grupopeca;
for($c=0; $c < $tam; $c++){
$grupopeca .= $peca[$c].';'. $qtd[$c].';'.$valorunitario[$c].';';
#echo $grupopeca;
}
Now, how do I separate this data when I go to give a select in the database?
(example if the array is size = 3)
The string will be like this:
Washer;10;5;Nut;10;6;Screw;10;7
I need to separate as follows into 3 variables:
$item
$Qtd
$valorunit
Item: Washer
Qtd: 10
Valor Unit: 5
Item: Nut
Qtd: 10
Valor Unit: 6
Item: Paraduso
Qtd: 10
Valor Unit: 7
If there is any better logic to do this, I accept suggestions.
Look at the problems you can have with a multivariate column, 1 and 2. The ideal would be: Normalize values separated by comma for new table
– rray