Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to include IF condition inside a HTML Table

I need to use IF condition to check whether a PHP variable is equal to some value or not.
Here is my try..

while ($row = $result -> fetch_assoc())
{
    $qDate .= '<td style="text-align:center"><b>'.$row['Date'].'</td>';
    $qStatus .= '<td style="text-align:center">'.$row['Status'].'</td>';
}

Then I need to include a html table into a phpvariable as below.

if($result->num_rows > 0){
$messagenew.= '
    <table style="top: 15px; left:10px; " border=1>

        <tbody>
            <caption style="color: rgb(241, 239, 243);background: rgb(1, 32, 65); ">Status</caption>
            <tr>
                <td style="text-align:center"><b>Date</td>'.$qDate .'
            </tr>

            <tr>
                <?php if($qStatus=="Not Received"){?>
                  <td style="text-align:center;background-color: red;"><b>Status</td>'.$qStatus_SEQ .'
                <?php}?>
                <?php else{ ?>
                   <td style="text-align:center;background-color: Green;"><b>Status</td>'.$qStatus_SEQ .'
                <?php } ?>                  
                
            </tr>

        </tbody>
    </table>
';

    
}
else{
    $messagenew.= 'Data is not Available';
    
}

I have enclosed php code with tags. But still I am not getting the required output. Rather than highlighting the value I can see my Header(Status) have highlighted.And the table were also messed up. Can someone help me on this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Update:messagenew variable can be seen when mail generated.Mail generating code not attached here.

>Solution :

Since you have mentioned Your Headers are only changing, You better to assign the rule when you are fetching data. Try below..

while ($row = $result -> fetch_assoc())
{
    $qDate .= '<td style="text-align:center"><b>'.$row['Date'].'</td>';
    if($row['Status']=='Not Received') {
        $qStatus .= '<td style="text-align:center;background-color: red;">'.$row['Status'].'</td>';
     }
    else{
   $qStatus .= '<td style="text-align:center;background-color: green;">'.$row['Status'].'</td>';
     }

}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading