Geoff_S
Geoff_S

Reputation: 5105

Color coding html table cell based on SQL flag value

So I finally have a SQL query working to take 3 conditions from my DB table and set a flag based on them.

Here is the Statement:

UPDATE staging 
SET  `miuFlag` =1 
WHERE  `lowSideMIUNumArriv` =    `lowSideMIUNumDepart` 
AND  `miu` =  "No"

Now my database table has a column called 'miuFlag' with either ones or zeroes. Based on this value, I want one of my html table values to be red or green (0=red, 1=green).

Here is the affected html table row:

        <td><? echo $row['miu'];?>&nbsp;</td>

I know I can color this row's font by using style inside of the td element, but how exactly would I create the condition to style one color for miuFlag = 0 and another for miuFlag = 1?

Upvotes: 0

Views: 549

Answers (3)

m i c h a e l
m i c h a e l

Reputation: 85

I think it would be something like this:

<td class="<? echo ($row['miu'] == 0) ? "redstyle" : "greenstyle"); ?>">&nbsp;</td>

Upvotes: 1

Farhad Hossen
Farhad Hossen

Reputation: 273

You can try this code:

<td styel="<?php $row[miuFlag] == 1 ? 'color:green' : 'color:red' ?>"><?= $row['miu'];?>&nbsp;<td>

Upvotes: 1

Bookin
Bookin

Reputation: 282

HTML:

<td class="<?php echo (int)$row['miu']?'red':''?>"><? echo $row['miu'];?>&nbsp;</td>

CSS

.red{
    color:red;
}

Upvotes: 1

Related Questions