CodeIgniter Forums
return row to view help - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: return row to view help (/showthread.php?tid=45866)



return row to view help - El Forum - 10-09-2011

[eluser]Unknown[/eluser]
ok, im just having a huge brain fart here... im trying to return a single row to my view, but im missing a step along the way. How do I pass a sinlge row of data from my db threw my controller and into my view page?

Model snip:
Code:
public function get_tech_name($id) {
        $query = $this->db->get_where('techs', array('id' => $id));
        $row = $query->row();
        
        $name = $row->first_name . " " . $row->last_name;
        return $name;      

    }


Controller snip:
Code:
public function index()
{
    $name = $this->users_model->get_tech_name($this->session->userdata('techid'));
    $data['tech_name'] = $name;

    $data['query'] = $this->home_model->get_company_list();

    $this->load->view('home_view', $data);
      
}

View: (The Welcome line is where I simply want to print the techs name, but it only prints the first letter of their name, because im doing it the wrong way lol)
Code:
<body>

<div id="container">
<h2>Welcome, &lt;?php echo $query['fname'];// . " " . $lname; ?&gt;</h2> | Logout Link
    </br>
    </br>    
<div id="body">
    
    Company list:
    </br>    
    &lt;?php foreach($query as $item): ?&gt;
    
   link disabled ="&lt;?php base_url();?&gt;home/view/&lt;?php echo $item['id']; ?&gt;">&lt;?php echo $item['company_name'];     </br>
        
    &lt;?php endforeach; ?&gt;

</div>

</div>

&lt;/body&gt;
&lt;/html&gt;