[eluser]digitaldivaradio[/eluser]
I have 2 questions... this is a user modification page that I am working on. I have a model that gets the user information with a couple joins.
1. I am trying to display their user id, the primary key on the users table. I get '1' in output on every record. It doesn't happen on the pages where I don't need a join. all tables use 'id' to name the primary key. How do I specify that I am talking about the users.id and not some other id?
2. Dropdowns - I have a couple dropdowns that are being populated by their own database model. How do I get the dropdown to default to the users record? Right now they load perfectly, but they are always on option 1. I want to have it be on option 3 or 4 if that's what is stored in the database.
MODEL:
Code:
function get_user_detail() {
$userid = $this->uri->segment(3);
$this->db->select('*');
$this->db->from('users');
$this->db->where('users.id', $userid);
$this->db->join('user_occupation', 'users.occupation = user_occupation.id', 'inner');
$this->db->join('location_country', 'users.country = location_country.id', 'inner');
$this->db->join('user_types', 'users.user_type_id = user_types.id', 'inner');
$this->db->join('sales_reps', 'users.sales_rep_id = sales_reps.id', 'inner');
$q = $this->db->get();
if($q->num_rows() > 0) {
foreach($q->result() as $row) {
$data[] = $row;
}
return $data;
}
}
CONTROLLER:
Code:
function user_mod() // page
{
$this->load->model('admin_users_model');
$data['records'] = $this->admin_users_model->get_user_detail();
// get the dropdown data from the database
$this->load->model('dropdowns_model');
$data['country_data'] = $this->dropdowns_model->get_country_dropdown();
$data['occupation_data'] = $this->dropdowns_model->get_occupations_dropdown();
$data['sales_rep_data'] = $this->dropdowns_model->get_sales_rep_dropdown();
$data['states_data'] = $this->dropdowns_model->get_state_dropdown();
$data['user_type_data'] = $this->dropdowns_model->get_user_types_dropdown();
$data['page_title'] = 'Admin User Modification, Design Center - Artistic Paver Mfg. ';
$data['main_content'] = 'admin_area/user_mod';
$this->load->view('inc/admin/template', $data);
}
VIEW:
Code:
<?php if(isset($records)) : foreach($records as $row) : ?>
<h1>User Account Information - <?php echo $row->first_name; ?> <?php echo $row->last_name; ?></h1>
<p> <?php echo anchor('admin/modify_user/'.$row->id, 'edit user information');?></p>
<div class="dc_user_detail">
<table>
<tr>
<td>User ID:</td>
<td><?php echo $row->id; ?></td>
</tr>
<tr>
<td><?php echo form_label('Occupation:', 'occupation', ''); ?></td>
<td><?php echo form_dropdown('occupation', $occupation_data, '$row->occupation_title'); ?></td>
</tr>
...