Welcome Guest, Not a member yet? Register   Sign In
[solved]Concept of CI - Get DB results from Controller/Model and send to View.


This is how I take data from DB to my view. I do it inside the view, directly, showing the user name who's logged
in his profile.

// This code is part of a View
<div id="info_name_profile">
  $login = $_SESSION['username'];
  $query = $this->db->query("SELECT * FROM USERS WHERE login = '$login';");

  $row = $query->row();
  echo $row->name;

...but, I'm searching how to do this but from a Controller/Model and send it to the VIEW? another way to do this? a standard CI way?

Any tip would be appreciated.


***********UPDATE, solved. I'm a noob:

I've solved this question looking again at the video tutorial: http://codeigniter.com/tutorials/watch/blog/

In my Model there is a function where i take the data from DB. Then, in the Controller I got the result of that DB operation and send it to my view through:
$data['nameLogged'] = $res->name;

//And then to the view:
$this->load->view('template', $data);

//In the view, just echo the var :
&lt;?php echo $nameLogged; ?&gt;

Theme © iAndrew 2016 - Forum software by © MyBB