Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
flash negative color, i want to change color of negative value from black to red, and positive in green

i have this format table of price and want to display in table with flash color anyhelp with this what to do ? decode encode fetch? i have this format table of price and want to display in table with flash color anyhelp with this what to do ? decode encode fetch?

<?php
$bidRateUNI = 10 ;
$UNIUSDBUY = 22;  
$UNIUSDSELL = 33;
$BUY1UNI = $bidRateUNI - $UNIUSDBUY;
$BUY2UNI = $bidRateUNI - $UNIUSDSELL;
$SELL1UNI = $UNIUSDBUY - $bidRateUNI;
$SELL2UNI = $UNIUSDSELL - $bidRateUNI;

?>
<html>
<body>

<title>untitled</title>
<style>
    .negative { color : red; }
    .positive { color : green; }
</style>
<?php
echo '<table>
   <tr>
        <td class="plusmin">$SELL2UNI</td>
        <td class="plusmin">$SELL1UNI</td>
        <td>$9,500</td>
        <td class="plusmin">$BUY2UNI</td>
        <td class="plusmin">$BUY1UNI</td>
    </tr>
    <tr>
        <td class="plusmin">$53.12</td>
        <td class="plusmin">+2.5%</td>
        <td>£110,000</td>
        <td class="plusmin">$10,000</td>
        <td class="plusmin">+15.57%</td>
    </tr>
</table>';
?>

<script>
function MakePosNeg() {
  var TDs = document.querySelectorAll('.plusmin');

  for (var i = 0; i < TDs.length; i++) {
    var temp = TDs[i];
    if (temp.firstChild.nodeValue.indexOf('-') == 0) {temp.className = "negative";}
    else {temp.className = "positive";}
  }
}
onload = MakePosNeg()
</script>
</body>
</html>

**; help with some good info** 
;help with some good info
';help with some good info

**; help with some good info** 
;help with some good info
';help with some good info
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Your question is unclear. What do you want to be coloured? The column? The row? The cell?

Are you colouring the PHP output?

However, the simplest method would be to use the ternary operator in PHP rather than using javascript. A ternary operator is essentially a short-hand if/else statement. Here is an example (based on the assumption you want the font of the PHP code coloured).

echo "<td style='color: " . $BUY1UNI < 0 ? 'red' : 'green' . "'>" . number_format($BUY1UNI, 3) . "</td>";

about 4 years ago · Juan Pablo Isaza Relatório

0

You have messed up with your code. you don't need javascript for that as @jeff Vdovjak and you have also opened php tags unnecessarily which makes confusion. I guess following code will help you

<?php

$bidRateUNI = 10 ;
$UNIUSDBUY = 22;
$UNIUSDSELL = 33;
$BUY1UNI = $bidRateUNI - $UNIUSDBUY;
$BUY2UNI = $bidRateUNI - $UNIUSDSELL;
$SELL1UNI = $UNIUSDBUY - $bidRateUNI;
$SELL2UNI = $UNIUSDSELL - $bidRateUNI;
?>
<html>
<body>

<title>untitled</title>

<table>
   
        <td class="plusmin" style='color:<?php if($SELL2UNI<0){echo"red";}else{ echo"green";}?>'><?php echo $SELL2UNI?></td>
        <td class="plusmin" style='color:<?php if($SELL1UNI<0){echo"red";}else{ echo"green";}?>'><?php echo $SELL1UNI?></td>
        <td>$9,500</td>
        <td class="plusmin" style='color:<?php if($BUY2UNI<0){echo"red";}else{ echo"green";}?>'><?php echo $BUY2UNI?></td>
        <td class="plusmin" style='color:<?php if($BUY1UNI<0){echo"red";}else{ echo"green";}?>'><?php echo $BUY1UNI?></td>
    </tr>
    <tr>
        <td class="plusmin">$53.12</td>
        <td class="plusmin">+2.5%</td>
        <td>£110,000</td>
        <td class="plusmin">$10,000</td>
        <td class="plusmin">+15.57%</td>
    </tr>
</table>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda