-1
The site has 3 checkbox, but I will implement much more. The problem is that my code is not very cool, because I need to calculate the total value
Code is like this:
$hena = filter_input(INPUT_POST, "hena", FILTER_SANITIZE_MAGIC_QUOTES);
$simples = filter_input(INPUT_POST, "simples", FILTER_SANITIZE_MAGIC_QUOTES);
$maquiagem = filter_input(INPUT_POST, "maquiagem", FILTER_SANITIZE_MAGIC_QUOTES);
$valorHena = 20; // Valor da Hena
$valorSimples = 15; // Valor da Simples
$valorMaquiagemIndividual = 100; // Valor da maquiagem individual
if (isset($hena) && !isset($simples) && !isset($maquiagem)) {
$dado->setResultado($valorHena);
}elseif (isset($simples) && !isset($hena) && !isset($maquiagem)) {
$dado->setResultado($valorSimples);
}elseif (isset($maquiagem) && !isset($hena) && !isset($simples)) {
$dado->setResultado($valorMaquiagemIndividual);
}elseif (isset($hena) && isset($simples) && !isset($maquiagem)) {
$resultado = $valorHena + $valorSimples;
$dado->setResultado($resultado);
}elseif (isset($hena) && isset($maquiagem) && !isset($simples)) {
$resultado = $valorHena + $valorMaquiagemIndividual;
$dado->setResultado($resultado);
}elseif (isset($maquiagem) && isset($simples) && !isset($hena)) {
$resultado = $valorMaquiagemIndividual + $valorSimples;
$dado->setResultado($resultado);
}elseif (isset($maquiagem) && isset($simples) && isset($hena)) {
$resultado = $valorHena + $valorSimples + $valorMaquiagemIndividual;
$dado->setResultado($resultado);
}
As you can see it’s quite confusing, wanted to get better and tried everything someone could give a hint ?
The way we’re seeing it is not confused, it’s impossible to understand, kkkk, but getting this code I don’t see why you want to improve. I ask: is it working well? If it is then good!
– user60252
kkk yes it works however this code is that I will have to increment more than 10 elseif.
– heitor_deep
has the switch case that tb will give the same trouble
– user60252
has how you click edit in my answer, copy and paste in your question
– user60252
I also thought of the switch However in the case part I would need to pass 2 information at the same time and I do not know how to :/
– heitor_deep
is boy, with 10 more inputs will give a work even if Else. I’m thinking here a way to put in an array
– user60252
You have a sense of how you would do that?
– heitor_deep
Hello, this looks like code review.
– Edilson
I know you’re trying to help relax. I’ll try to find a way if I get a code cuter kk I put here so other people see it too
– heitor_deep
Leo, I found a solution, but I don’t know if it’s good or bad, but it’s a good one. Is ternary $result = (isset($hena))? $result + $valueHena : $result; $result = (isset($simple))? $result + $valueSimples : $result; $result = (isset($makeup))? $result + $valueIndividual : $result;
– heitor_deep
Boy, I woke up late and already put an answer using array, kkk, Who goes to sea loses its place and who goes to the wind loses its seat. ;)
– user60252