I'm having a question about how best to implement a method that traverses a common select using DAO standard with PDO.
It would be appropriate for me to do this, my whole code in the view:
$conexao = new PDOUtil ();
$consulta = $conexao->getStance()->prepare( "SELECT id_pagina, tema FROM pagina" );
$consulta->execute ();
?>
<select required="" name="id_pagina">
<option disabled="">Selecione uma página</option>
<?php while ($linha = $consulta->fetch(PDO::FETCH_OBJ)) { ?>
<option value="<?php echo $linha->id_pagina;?>"><?php echo $linha->tema;?></option>
<?php } ?>
</select>
Or it would be best to do all this part within my DAO class example by blending HTML and PHP within querys:
class Dao
$conexao = new PDOUtil ();
public function buscarTudo() {
$consulta = $conexao->getStance()->prepare( "SELECT id_pagina, tema FROM pagina" );
$consulta->execute ();
echo "<select required="" name="id_pagina">";
echo"<option disabled="">Selecione uma página</option>";
while ($linha = $consulta->fetch(PDO::FETCH_OBJ)) {
echo "<option value=" $linha->id_pagina;">"
echo "$linha->tema;?></option>"
}
echo "</select>";
}
and then just call this method inside my view. Would you have another suggestion?
If the code is wrong do not call it is why I typed it right here, thank you all.