Join 2 if’s Php

Asked

Viewed 177 times

-1

it is possible I join two if’s almost in a row?

    ' <p>Trabalhador (4) Validade:';
  if ($exibe['MedicaValidade4'] != '0000-00-00')
 {
  if (strtotime($exibe['MedicaValidade4']) < time()) 
   {
    echo '<span style="color:red">'.$exibe['MedicaValidade4'].'</span>';
    echo '<a href="MostrarMedica4.php?id='. $exibe['id'].'">&nbsp; Ver PDF</a>';
  } else {
    echo $exibe['MedicaValidade4'];
    echo '<a href="MostrarMedica4.php?id='.$exibe['id'].'">&nbsp; Ver PDF</a></p>';
  }
}





<p><b>Projectista: </b></p>
       <p>Projectista Numero: '.$exibe["ProjectistaNumero"].'</p>
       <p>Projectista Validade:';

All this inside PHP

What I want to do is to see if the Medicavalidade date is set and check if the date is past today. If it passes, the numbers turn red. If it doesn’t go black. If no data is filled in it shows nothing

2 answers

0


I don’t quite understand your question. But from what I understand I will try to do, if I’m wrong, edit your question adding more details.

You will create an if to know if the date is filled in, and inside that if check if the date has passed. Simple, an if/Else within an if. It should look something like this:

if($exibe['MedicaValidade'] != NULL) { //Verifica se o número foi preenchido.
     $diaAtual = date("Y-m-d"); // Recebe o dia atual.
     if($exibe['MedicaValidade'] > $diaAtual) { // Compara, caso o dia recebido seja maior que o dia atual...
           echo "O Dia ja passou. Faça aqui a mudança da cor.";
     } else { Se não...
            echo "O dia ainda não passou.";
} else { // E caso a data não esteja preenchida.
        echo "Preencha a data!";
}

Well, I didn’t test the code, but I think there might be a north. I hope I helped.

  • I’m having a hard time because of the clicks. I’ll change my question to see if you can help me

0

There’s no reason to have two If, like you did. You could have used the operator && to join conditional expressions

Thus

If ($condicao_1 == true && $condicao_2 == true)

That is, above you are saying that the first and second condition must be true

Browser other questions tagged

You are not signed in. Login or sign up in order to post.