Since I don't know where and how you're using or re-using $this->rows[]
as you haven't posted about it, I will change a bit your code:
public function get_data()
{
$sql = "SELECT id_especialidad,
descripcion
FROM especialidad";
$result = array();
foreach($this->dbh->query($sql) as $row)
{
$result = $row;
}
return $result;
}
Given $this->dbh->query
is the PDO query
, if you print_r
the result you get from get_data
it should give you something similar to:
Array(
[0]=>Array([id_especialidad]=>1
[0]=>1
[descripcion]=>test
[1]=>test
)
[1]=>Array([id_especialidad]=>2
[0]=>2
[descripcion]=>test2
[1]=>test2
)
)
And you can easily read it like this:
<select>
<?php
$data = $db->get_data();
foreach ($data as $item)
{
?>
<option value="<?php echo $item["id_especialidad"]; ?>"><?php echo $item["descripcion"]; ?></option>
<?php
}
?>
</select>
If you're getting more than 9 results where it should have been only 9 I can only think there might be a problem with $this->rows[]
not being cleared after used or something alike.