How do I use my select that is in my funções.php
in this table that is in my estoque.php
, I already did the script I just can not call the $resultado
that is in the function to use in foreach
.
STOCK.PHP
selecionar_produtos();
?>
<div class="container">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Nome</th>
<th>Marca</th>
<th>Modelo</th>
<th>Quantidade</th>
<th>Estado</th>
<th>Opções</th>
</tr>
</thead>
<tbody>
<?php foreach ($resultado as $key) :?>
<tr>
<td><?php echo $key->nome;?></td>
<td><?php echo $key->marca;?></td>
<td><?php echo $key->modelo;?></td>
<td><?php echo $key->quantidade;?></td>
<td><?php echo $key->estado;?></td>
<td>
<a href="mysql/update.php?id=<?php echo $key->id; ?>" class="btn btn-info">Editar</a>
<a href="mysql/delete.php?id=<?php echo $key->id; ?>" class="btn btn-danger">Deletar</a>
</td>
</tr>
<?php endforeach;?>
FUNCOES.PHP
<?php
function selecionar_produtos(){
require "mysql/pdo.php";
try{
$selecionar = "select * from estoqueprodutos . produtos";
$stmt = $pdo->prepare($selecionar);
$stmt->execute();
$resultado = $stmt->fetchAll(PDO::FETCH_OBJ);
} catch (PDOException $error){
echo "Erro:\n" . $error->getMessage();
}
}
?>