Good afternoon, guys, I have a problem. I'm a beginner in object-oriented programming and I'm trying to do a select / option that takes values from within the database into an employee table. The problem is that when I make the request to the bank for a Select class it returns the connections to the bank, I am not able to return the data and place them inside an option.
class Select {
private static $conn;
public function __construct() {
$this->conn = new Conexao();
}
public function Selecionar(){
try{
$pdo = $this->conn->Conectar()->prepare('SELECT * FROM funcionario');
$pdo->execute();
$pdo->fetchAll(PDO::FETCH_ASSOC);
foreach ($pdo as $resultado){
echo $resultado;
var_dump($resultado);
}
} catch (PDOException $ex) {
echo"<script language='javascript' type='text/javascript'>alert('Houver um erro, entrar em contato com administrador.('.$ex->getLine().');window.location.href='/DivinaBeleza/login.php';</script>";
}
}
}
and here is the HTML:
<select>
<option value="1">Chosen</option>
<?php
$a = new Select();
$a->Selecionar();
?>
<option value="<?php echo $result['idFuncionario']; ?>"><?php echo $result['funcaoFuncionario'];?></option>
</select>
I'm not understanding how to give the return or pass the data to the page in html by creating objects and instantiating them. Only then put in an option. Guys give me a light, I've been trying for some days and I could not. Appreciate. What appears to me is the connection, if I use var_dump or echo in the select () method in the $ result variable, it shows me the object connection stored inside the array.