Best way to pass and display one record in a form (in a view) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Best way to pass and display one record in a form (in a view) (/showthread.php?tid=25978) |
Best way to pass and display one record in a form (in a view) - El Forum - 01-02-2010 [eluser]jrichey[/eluser] I want to create a detail page where the user has selected a single item from a list. Here is my controller function: function edit_view(){ $data['title'] = 'Edit Domain'; $this->db->where('id', $this->uri->segment(3)); $data['query'] = $this->db->get('domains'); $this->load->view('domain_edit', $data); } In my view, I am showing the data in form fields for editing such as: <input type="text" name="domain" value="data value goes here" /> Right now I have it working by using a foreach statement, even though I know it's only going to return one row. Is there a better way to do this other than using a foreach? Best way to pass and display one record in a form (in a view) - El Forum - 01-02-2010 [eluser]Colin Williams[/eluser] You can get $query->result() for an array of objects, or just do $query->row() for a single row Best way to pass and display one record in a form (in a view) - El Forum - 01-03-2010 [eluser]Johan André[/eluser] I would also recommend not accessing the db directly in the controller. Maybe this was only an example though... |