I have a div that is made up of some text fields, and a button that calls a js function that duplicates this div if the user clicks ...
Example:
Code:
<divid="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>
OK, now what I need:
When I submit a form in my form, field values are passed via POST in the form of an array:
item []
qtd []
valueunit []
So if the user duplicates the 3x div for example, the array contains the 3 values entered ...
Now how do I save this array in the database?
-I thought of putting everything together into a string, separating by; (semicolon) ... and save in a column of the bank, this I was able to do 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 give a select in the database?
(example if the array is size = 3)
The string will look like this:
Washer; 10; 5; Nut; 10; 6; Screw; 10; 7
I need to sort the following into 3 variables:
$ item
$ qtd
$ valorunit
Item: Item #: 5
Item: 6
Item: Qtd:Item: 7
If there are any other better logic to do this, I accept suggestions.