I'm doing a small practice project where I take out information from the database and show it in a view as a "profile" type.
At the moment of showing it, I get an indefinite variable error, but that variable is already brought in the query
This is the method of the user model that brings the information from the database:
function datosUsuario($id){
$this->db->select('nombre, apellido, direccion, telefono, correo');
$this->db->where('id_usuario', $id);
//$this->db->limit(1);
$query = $this->db->get('tbl_usuarios');
return $query->result_array();
}
This is the view:
<h1>Bienvenido <span id="usuario">@<?= $id; ?></span></h1>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-1">
<label for="nombre">Nombre:</label>
<p><?= $nombre; ?></p>
</div>
</div>
</div>
and finally, this fragment, which is the function of the controller:
function index(){
if($this->session->userdata('login_ok'))
{
$data = $this->usuario->datosUsuario((string)$this->session->userdata('id_usuario'));
$data['id'] = $this->session->userdata('id_usuario');
$this->load->view("perfil", $data);
}else{
Redirect('inicio/index', 'location');
}
}