Welcome Guest, Not a member yet? Register   Sign In
Best way to pass and display one record in a form (in a view)
#1

[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?
#2

[eluser]Colin Williams[/eluser]
You can get $query->result() for an array of objects, or just do $query->row() for a single row
#3

[eluser]Johan André[/eluser]
I would also recommend not accessing the db directly in the controller.
Maybe this was only an example though...




Theme © iAndrew 2016 - Forum software by © MyBB