Join 2 if's Php

-1

Can 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:';

This is all within PHP

What I want to do is see if the Medicaid date is pre-set and check if the date passes today. If you pass, the numbers are red. If the numbers are not black. If no data is entered it shows nothing

    
asked by anonymous 06.06.2014 / 15:55

2 answers

0

I did not quite understand your question. But from what I understand I'll try to do, if I'm wrong, edit your question by adding more details.

You will create an if to know if the date is filled, and within that if check if the date has passed. Simple, an if / else inside an if. It should look 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 did not test the code, but I think I can have a north. Hope this helps.

    
07.06.2014 / 06:58
0

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

So

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

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

    
14.03.2017 / 10:41