Q:

Fetch single record from database and display in text box using Codeigniter

I have multiple records in database.
When I click on any id all records should be displayed in a textbox using Codeigniter.
i have two tab when i click on userid page automatically refreshed and i am getting userid in URL and tab redirect to 1st tab.
I don't want like this.I have to display record on 2nd tab only when i click on userid

I tried the following code, why doesn't it work?
Controller 
public function update_retrive()
{
$id = $this->uri->segment(3);
$this->load->model("model_add_user");
$d=$this->model_add_user->update_retrive($id);
$data['posts'] = $d;
}

Model 
public function update_retrive($userId)
{
$this->db->where('userId',$userId);
$this->db->from('add_user');
$q = $this->db->get();
return $q;
}

View 
<div id="btnclick" style="display: none">
<?php
foreach ($posts->result() as $post)
{
?>
<input type="text" name="userId" placeholder="USER ID" style="width:200px" value='<?php echo $post->userId;?>'>&nbsp;
<input type="date" name="date" style="width:200px" value='<?php echo $post->date;?>'>
<input type="text" name="firtsname" placeholder="FIRST NAME" style="width:200px" value='<?php echo $post->firtsname;?>'>&nbsp;
<input type="text" name="middlename" placeholder="MIDDLE NAME" style="width:200px" value='<?php echo $post->middlename;?>'>&nbsp;
<input type="text" name="lastname" placeholder="LAST NAME" style="width:200px" value='<?php echo $post->lastname;?>'>&nbsp;
<input type="text" name="mobileno" placeholder="ENTER MOBILE NO." style="width:200px" value='<?php echo $post->mobileno;?>'>&nbsp;
<input type="text" name="landline" placeholder="LANDLINE No." style="width:410px" value='<?php echo $post->landline;?>'>
<textarea name="address" placeholder="ENTER ADDRESS" style="width:410px" ><?php echo $post->address;?></textarea>
<input type="text" name="city" placeholder="CITY" style="width:200px" value='<?php echo $post->city;?>'>&nbsp;
<input type="text" name="locality" placeholder="LOCALITY" style="width:200px" value='<?php echo $post->locality;?>'>
<input type="text" name="email" placeholder="ENTER EMAIL" style="width:410px" value='<?php echo $post->email;?>'></br>
<input type="submit" class="submit" name="UPDATE" value="UPDATE" >
<input type="submit" class="submit" name="cancel" value="Cancel" >
<?php }
?>
</div>

A:

on your model bro should be like this
public function update_retrive($userId)
{
$this->db->where('userId',$userId);
$this->db->from('add_user');
$q = $this->db->get();
return $q->result();// this will get all the result inside the database
}

will in your view at ease.
the the controller should be like this
public function update_retrive()
{
$id = $this->uri->segment(3);
$this->load->model("model_add_user");
$d=$this->model_add_user->update_retrive($id);
$data['posts'] = $d;
$this->load->view('yourview',$data);
}

controller answered by: @ricky
note: re-check the page your trying to access.

