Good afternoon,
I generate the following query to the database to bring a list with the id and the name of a product
function getActivos(){
// armamos la consulta
$query = $this->db
->select("*")
->from("tipo_activo")
->order_by("id_tipo_activo")
->get();
// si hay resultados
//echo $this->db->last_query();exit;
if ($query->num_rows() > 0) {
// almacenamos en una matriz bidimensional
foreach($query->result() as $row) $arrDatos[htmlspecialchars($row->id_tipo_activo, ENT_QUOTES)] = htmlspecialchars($row->nombre_tipo_activo, ENT_QUOTES);
$query->free_result();
return $arrDatos;
}
}
in the controller I have the following function to load the result of the query:
public function modificar($id=null)
{
//obliga a que se le pase un parametro por la url, que es el id del activo a modificar
if(!$id){show_404();}
$datos=$this->activo_model->getTodosPorId($id);
if(sizeof($datos)==0){show_404();}
//print_r($datos);exit;
// obtenemos el array de activos y lo preparamos para enviar
$getdatos['arrayActivos'] = $this->activo_model->getActivos();
//print_r($getdatos);exit;
$this->layout->view("modificar",compact('datos','id', 'getdatos'));
}
and in the view I post the list as follows:
<p>
<label for="tipo_activo" >Tipo Activo:</label>
<select name="tipo_activo" class="form-control" value="<?php echo set_value_input(array(),'tipo_activo','tipo_activo')?>" autofocus="true" >
<option selected value="0"></option>
<?php foreach ($arrayActivos as $i => $nombre_tipo_activo) {
echo '<option value"',$i,'">', $nombre_tipo_activo,'</option>';
}
?>
</select>
</p>
The problem I have is that when I call the view from the controller as it relates previously:
$this->layout->view("modificar",compact('datos','id', 'getdatos'));
I do not load the list of the query that I made, in fact, if I do it in the following way:
$this->layout->view("modificar",$getdatos);
if I load it, but I can not leave it that way because I also need to load $ data and $ id that are being loaded with a compact, if I charge it like this:
$this->layout->view("modificar",$getdatos, $id, $datos);
does not work for me either, what can I do to load the three variables and load the list?
thank you very much