-1
I have script using foreach that generates the variables $d, $m, that receive the value of a mysql query and puts this value in the input
echo "
<input type='text' name='tipo' value='".$d."'>
<input type='text' name='metragem' value='".$m."'>
";
Then I wanted each field to be unique, because the query returns several lines, so I added $n
$n = 0;
foreach($unidades as $unidade){
$n++
echo "
<input type='text' name='tipo".$n."' value='".$d."'>
<input type='text' name='metragem' value='".$m."'>
";
}
so far so good, but now I need to join all in a single variaval $dtotal and $mtotal, ex:
$mtotal = 'tipo'.$n1.'|'.'tipo'.$n.'|'.'tipo'.$n(quantos n tiverem);
"wanted every field to be unique", but what is the reason for this, identify in the
javascript
? If it is, it would be better to define the id and not the unique name. Using the same name (tipo[]
) you can take an array of values and easily join by making aforeach
, there are several examples here at Sopt.– Ricardo Pontual
Leandro, can reply to us if you need to "join" the fields at the time you are assembling the page, to display the total, or when you post the page, read all fields and join to add the value?
– Ricardo Pontual