2

This php code generates a table with some information like: temperature, water health, ph level and other things ...

if (count($auxGateway->getMaquina()) > 0)
{
    foreach($auxGateway->getMaquina() as $maq)
    {
        echo '<div class="cont-maq-uni">';//Cria a div para cada maquina
        echo '  <table class="maq">';//Cria uma tabela
        echo '      <tr>';
        echo '          <td colspan="2">';
        echo '              <h2 class="maq-head">'.$maq->getNome().'</h2>';
        echo '          </td>';
        echo '      </tr>';
        foreach($maq->getVariavel() as $var)
        {
            echo '  <tr class="maq">';
            echo '      <td class="maq">';
            echo '          <p class="n_font maq">'.$var->getNome().'</p>';
            echo '      </td>';
            echo '      <td class="maq">';
            echo '          <p class="n_font maq">'.(floatval($var->getValor()) * floatval($var->getMultiplicador()) + floatval($var->getSomador())).' '.$var->getUnidadeValor().'</p>';
            echo '      </td>';
            echo '  </tr>';
        }
        echo '  </table>';
        echo '</div>'; 
    }
}

so I need to create a code to show some images if that information is bigger or less. For example: if 'temperature' <30 then it will show the image (notgood.jpeg). The problem is: how do I name these values since they are inside the MYSQL database? How will I name each row in the table?

Thank you guys!

4
  • Which values where in the database? The temperature or the filename of the image?Please describe your question and problem more particularly . Commented Nov 18, 2017 at 11:41
  • @ToyRobotic The temperature and another informations are in the database. They are update by an ip (gateway). Commented Nov 18, 2017 at 11:52
  • Why didn't you do something like this? if( $var->getTemperature() > maxValue) .... // your information image else // another information image ? Sorry, but I didn't get your problem Commented Nov 18, 2017 at 11:56
  • The if (count($auxGateway->getMaquina()) > 0) { is superfluous. Commented Nov 18, 2017 at 13:48

1 Answer 1

1

You can use if..else.. or ternary operators

echo '<img src="' . ($var->getTemperature() < 30 ? 'notgood.jpeg' : 'good.jpeg') . '">' # using ternary operators;

This will give, if $var->getTemperature() < 30 <img src="notgood.jpeg"> else <img src="good.jpeg">

Sign up to request clarification or add additional context in comments.

Comments

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.