I am updating a section that uses mysql to PDO to deploy in a {html_options} of Smarty , and something that works well in mysql I do not know how to do it with PDO
This is the original code that works well now:
//Mando estados
$q="SELECT id, estado FROM estados";
$data=$db->execute($q);
$idEstados=array();
$estados=array();
for ($i=0; $i<sizeof($data);$i++) {
array_push($idEstados,$data[$i]->id);
array_push($estados,$data[$i]->estado);
}
$smarty->assign('idEstados',$idEstados);
$smarty->assign('estados',$estados);
Then in the .tpl everything is shown correctly, including "selected" which is the most important to me, otherwise I would do a {foreach} to display the states.
<select name="destino_idEstado" class="form-control">
<option>Seleccione un Estado</option>
{html_options output="$estado" values="$idEstado" selected=$data->idEstado}
</select>
What I'm doing with PDO works fine if I do a {foreach}, but I need to use the "selected" and it's easier for me to do it with the {html_options} of smarty, but I do not know how to send the array from PDO so that work.
$sql1="SELECT id,estado FROM testados";
$stmt = $dba->prepare($sql1);
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$idEstado = $row['id'];
$estado = $row['estado'];
$smarty->assign('idEstado', $idEstado);
$smarty->assign('estado',$estado);
}
This way it does NOT mark error, it just does not display the corresponding one.
Could someone guide me?