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

[eluser]Asshai[/eluser]
Hello,

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.

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

  $row = $query->row();
    
  echo $row->name;
?&gt;
</div>


...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.

Ty.

***********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:
Code:
$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