0

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?

2
  • 1
    Are you opposed to javascript? because with the JQuery Library it should be possible and fairly easy. Commented Jun 8, 2017 at 20:08
  • I'm actually using some on this page because it's all being displayed in a datatable Commented Jun 8, 2017 at 20:10

3 Answers 3

1

HTML:

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

CSS

.red{
    color:red;
}
Sign up to request clarification or add additional context in comments.

3 Comments

I think this makes sense, except for the value of miuFlag. So I need the value of miuFlag (0 or 1) to dictate the color of the $row[miu]. If that makes sense
(int)$row['miu']?'red':'' - if 1 it will be red, if 0 it will be empty
Thank you so much, it's perfect!
1

You can try this code:

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

2 Comments

So does that mean, if miuFlag is 1 use green, else use red?
<td styel="<?php $row[miuFlag] == 1 ? 'color:green' : $row[miuFlag] == 0 ? 'color:red' : ''?>"><?= $row['miu'];?>&nbsp;<td> try this @TomN.
1

I think it would be something like this:

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

3 Comments

But if I'm not mistaken, that only applies to 0 and not the 1. Also, I need to check the value (0 and 1) of miuFlag in my database and then color the miu row.
That would work for both, assuming that you only have two values. The first part after the question mark is what happens if the value is 0, and the part after the colon is for any other value.
you lose one bracket

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.