2
I have a quote form with 70 products in which the user chooses the amount of products he wants from each one.
All are named with id P1, P2...P70 and are number type inputs.
<form method="post">
<input type="number" value="0" name="p1" id="p1">
<input type="number" value="0" name="p2" id="p2">
...
<input type="number" value="0" name="p70" id="p70">
</form>
I need a PHP function that only inserts items other than 0 (which is the default value) into a variable to mount a table that will be exported to excel.
Here’s what I got:
// Monta o cabeçalho da tabela
$data = '<table><tbody><tr><td>CABEÇALHO</td></tr>';
// Traz cada linha que o valor é diferente de 0
if($_POST['form']['p1'] != '0'){
$data .= '<tr><td>'.$_POST["form"]["p1"].'</td></tr>';
}
if($_POST['form']['p2'] != '0'){
$data .= '<tr><td>'.$_POST["form"]["p2"].'</td></tr>';
}
// Coloca o rodapé e fecha a tabela
$data .= '<tr><td>RODAPÉ</td></tr></tbody></table>';
The problem with what I did is that I would have to have 70 ifs, I believe there should be a simpler way, but I don’t know which.
it worked, thanks!
– Leandro Marzullo