-2
Good afternoon, people, I have a problem. I’m a beginner in object-oriented programming and I’m trying to make a select/option that gets values from within the database in an employee table. The problem is that when making the request to the database by a Select class it returns me the connections with the database, I am not able to return the data and put them within 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 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 getting how to give the Return or pass the data to the html page by creating objects and instantiating them. Just then put in an option. People give me a light, I’ve been trying for a few days and I couldn’t. I appreciate it. 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 connection object saved within the array.