0
I’m trying a condition on ELSE IF
that’s gone wrong, I’ve done some pretty similar things and I really don’t know what it is...
I have a table on my system, where it displays some information for the user, within it, has a field called payment, I had to put this field as input like text
, why the user can put or "PENDING" or put the date of payment, and so I ended up leaving the input as text.
Another field is called emissary where is the type date
and I need to compare days with this field.
Conditions are working, minus the
ELSE IF.
I need you to take the field emissary spend 30 days and the countryside payment is pending, it uses a certain class...
I tried to do this by picking up the difference of years/days/months from the date of emissary compared to the current date, and played on one condition.
Let’s go to the code:
<?php
$sql = "SELECT * FROM emissao_nf";
$resultado = mysqli_query($con, $sql);
while ($cont = mysqli_fetch_array($resultado)) {
$prazo = new DateTime ($cont['emissao']); // Data do banco em DateTime
$hoje = new DateTime(); // Data atual em "DateTime"
$intervalo = $prazo->diff( $hoje ); // Pegando a diferença de anos, meses e dias
if(substr_count($cont['pagamento'], 'PEN') > 0){
$mostra="status-p bg-warning"; //Pendente, amarelo
}elseif(substr_count($cont['pagamento'], 'PEN') > 0 && $intervalo->m >= '1') {
$mostra="status-p bg-danger"; //Passou 30 dias e está pendente, vermelho
}else{
$mostra="status-p bg-primary"; // Data de pagamento, azul
}
echo"
<tr>
<td><span class='".$mostra."'>".$cont['pagamento']."</span></td>
</tr>
"; ?>
The ELSE IF
does not work, not page error or anything... Can anyone help me? I think it’s wrong that I’m using a type text
for dates, however, I don’t know what I can do.
In this print, the idea would be that it was "PENDING" but in red... Today is day 09/06/2020
Your
elseif
it will never happen, because if his first conditionsubstr_count($cont['pagamento'], 'PEN') > 0
is exactly the condition ofif
, so you’re going intoif
before entering theelseif
. Puts if as elseif and elseif as if.– Benilson
Hello @Benilson, thanks for the reply, I will try!
– Sazan S.
That’s right, thank you very much! I didn’t pay attention to it, the next few times I won’t miss more, thank you and a great week.
– Sazan S.
Glad I could help.
– Benilson