Error passing variable

0

I'm trying to pass a variable, but it does not appear on the screen.

The error ...

Notice: Undefined index: operator_map in C: \ xampp \ htdocs \ System \ Views \ form_mapa_continua.php on line 58

Here is where I call the function:

$nome = $busca_mapas->busca_mapa($id);

Here is the function:

public function busca_mapa($id){
    $conexao = Database::getConnection();

    $busca = "SELECT * from mapa WHERE cod_mapa = $id;";
    $mapa = $conexao->query($busca);
    $retorno = $mapa->fetchAll(PDO::FETCH_ASSOC);

    return $retorno;

}    

Here is the html code where I print the variable (and that's where the error also appears):

<div class="disabled field">
    <label>Nome do operador</label>
       <input value="<?= $nome['operador_mapa'];?>" placeholder="<?=$nome['operador_mapa']?>">
</div>

The bank:

I can assure you that there is data in the bank.

    
asked by anonymous 04.12.2018 / 14:03

1 answer

3

You used fetchAll , which returns an array of results. As you are looking for the id, you will always have only one result, making $nome look similar to:

$nome = [
    0 => [
        'setor_mapa' => ...,
        'operador_mapa' => ...,
        ...
    ]
];

Thus, to display a value, you would need $nome[0]['operador_mapa'] ; or you use the fetch method, which already returns the result.

    
04.12.2018 / 15:00