0
I have a question about the best way to implement a method that runs through a common select using DAO standard with PDO.
It would be appropriate for me to do so, my entire 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 the best would be to do all this part within my example DAO class by mixing HTML and PHP inside the 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 within my view. You would have another suggestion?
If the code is wrong do not call is why I typed right here, I thank all.
I guess you didn’t get my question. I know the class responsibility of the question I posed would be the best way to create select without mixing html in the dao class
– André Martins
@André Martins the second paragraph does not answer? Or the answer would have to say pq the first option is better than the second vice versa?
– rray
More or less I would like an example thank you
– André Martins