I have the following function in PHP:
function ListarDependencias() {
$db = new Conexion();
$sql = $db->query("SELECT Id, Nombre FROM Dependencias;") or die (mysqli_error($db));
if($db->mysqli_num_rows($sql) > 0) {
$result = $db->mysqli_fetch_array($sql);
} else {
$result = null;
}
$db->liberar($sql);
$db->close();
return $result;
}
Which I want to use to fill the next select with the following code:
<select id="selDependencia" name="selDependencia" class="form-control" required >
<option value="0"><--Seleccione--></option>
<?php
foreach (ListarDependencias() as $dataDependencias) {
echo "<option value='".$dataDependencias['Id']."'>".$dataDependencias['Nombre']."</option>";
}
?>
I have only two records in my table, however it shows me in select 4 and only its first characters as shown in the following image:
I do not want to have to bring the database scripts to my presentation where the select is, I would like to be able to go through the array and show the data. So I appreciate any help you could give me. Maybe I'm calling wrong the values of my array that my query returns.