Value x PHP input

Asked

Viewed 69 times

0

Code is this:

Page edits:

<?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 an x value in the input, in the status column in the table page special characters like this appear: . For example, if in the input is 10 shows in the table column , if is 11 shows and so will.

1 answer

2


Do a check with if/Else and echo with the ascii character code: 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 for ease, it is best to make a function that receives $objProg->getst() as parameter and return the correct character.

If for some reason the character is empty, 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.