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.
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>';
}
}