Value x input PHP

0

Code is this:

Page editing:

<?php
    $id = "";
    $DsStatus = "";

    if(!empty($_GET['id'])){
        $id = $_GET['id'];

        $results = $controller->listar($id);
        $DsStatus = $results->getst();
    }

    <form action="../controller/progPrecontrole.php" method="POST" onsubmit="return valid();">
        <input type="text" id="st" name="st" value="<?php echo $DsStatus; ?>"/>
    </form>
?>

Table page:

<?php
   foreach ($controller->ListaPorTipoB() as $objProg) {
?>
    <tr>
        <td><p><?php echo $objProg->getst(); ?></p></td>
        <td><a class="color" href="edita.php?id=<?php echo $objProg->getid();?>"><p>Alterar</p></a></td>
    </tr>
<?php
    }
?>

I need that, if the value of $DsStatus is a value x in the input, in the column of the status in the page of the table appear special characters like this: ↓. For example, if in the input for 10 it shows in the table column ↓, if it is 11 shows ↑ and so it goes.

    
asked by anonymous 20.01.2016 / 14:08

1 answer

2

Do a check with if / else and echo the ascii code of the character: echo chr ($ cod_character).

Ex: echo chr (77); // This code displays an "M".

In the table you have this line:

<td><p><?php echo $objProg->getst(); ?></p></td>

Do a check like this:

<td><p><?php if($objProg->getst() == x) { echo chr($cod_ascii); } else { echo chr($outro_cod_ascii); } ?></p></td>

But to make it easier, it is better to do a function that receives the $ objProg-> getst () as a parameter and returns the correct character.

If for some reason the character is blank, use decimal code

&#8593;

PHP function you can use:

<?php
function RetornarCarctere($x)
{
    if($x == 10)
    {
        return "&#8595;";
    }
    else if($x == 11)
    {
        return "&#8593;";
    }

    // E assim vai...

}
?>

Implementing the function on the line I spoke of would look something like this:

<td><p><?php echo RetornarCarctere($objProg->getst()); ?></p></td>
    
20.01.2016 / 14:44