I created an accounts page wherein I can view all accounts from the database. Each of them has an action button called View More. If I press View More, additional details from the database will be displayed in textboxes. I want to get the ID for each of the row and pass it to the controller in order for it to be viewed. However, I can't seem to make them show in the boxes.
Expected: Image
Current: Image
Controller:
function viewmore()
{
$userid = $this->input->get('userid', TRUE);
$data['view'] = $this->model_accounts->viewmore_user($userid);
$data['main_content'] = 'view_adminviewmore';
$this->load->view('includes/admin_viewmore_template', $data);
}
Model:
public function viewmore_user($userid)
{
$query= $this->db->select('*')->from('accounts')->where('userid', $userid)->get();
return $query->result();
}
View for the Action Button:
<?php foreach($users as $row): ?>
<tr>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->address; ?></td>
<td class="action-button mobile-important">
<a href="<?php echo base_url() ."admin_accounts/viewmore/?id=". $row->userid ?>"> <button type="button" class="btn btn-custom-3">View More</button></a>
</td>
<?php endforeach; ?>
</tr>
View for displaying the data:
<?php foreach($view as $row): ?>
<br>
<p> First Name </p>
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->firstname; ?>">
<br>
<p> Last Name </p>
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->lastname; ?>">
<br>
<p> Username </p>
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->username; ?>">
<br>
<p> Address </p>
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->address; ?>">
<br>
<p> E-mail Address </p>
<input class="form-control" id="sel1" type="email" placeholder="" value="<?php echo $row->email; ?>">
<br>
<p> Contact Number </p>
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->contactnum; ?>">
<br>
<?php endforeach; ?>
If you are using CodeIgniter, why not use the Form Helper?
You can use code like this:
<?php echo form_input('sel1', $row->firstname); ?>
instead of:
<input class="form-control" id="sel1" type="text" placeholder="" value="<?php echo $row->firstname; ?>">
Read some more about it here: https://www.codeigniter.com/user_guide/helpers/form_helper.html
your action button
must be like this:
you can use
<?="hello word!!!" ?>
instead of<?php echo "hello word!!!" ?>
and
base_url()
return the root of your codeigniter folder that set inapplication->config->config.php
<a href="<?=base_url()." YOUR_CONTROLLER_NAME/viewmore/".USER_ID ?>View More</a>
link above return <a href="localhost/YOUR_CONTROLLER_NAME/viewmore?id=USER_ID>View More</a>
and your function viewmore()
must be change to function viewmore($id=0)
,this $id
give USER_ID from your url
and you better to know url in codeigniter contain this: Controller
/Function
/variable that you want pass to your function