[eluser]deongee[/eluser]
Hi All, I have a drop down list that updates the record when submitting the page but I have to refresh to get the correct data.
I'm testing the "
Status" drop downfield.
Controller:
Code:
function edit($account_id='', $platform =''){
if($account_id > ''){
$query = $this->db->get_where('db_accounts', array('account_id' => $account_id));
if(isset($query))
if ($query->num_rows() > '')
{
$row = $query->row_array();
}
//declare variables
$data['account_id'] = '';
$data['platform'] = '';
$data['name'] = '';
$data['location_city'] = '';
$data['location_country'] = '';
$data['status'] = '';
//pass field data
$data['faccount_id']['value'] = $row['account_id'];
$data['fplatform']['value'] = $row['platform'];
$data['fname']['value'] = $row['name'];
$data['flocation_city']['value'] = $row['location_city'];
$data['flocation_country']['value'] = $row['location_country'];
$data['fstatus']['value'] = $row['status'];
}
if(isset($account_id)){
$this->form_validation->set_rules('account_id', 'Account ID', 'trim|required');
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('platform', 'Platform', 'trim|required');
$this->form_validation->set_rules('status', 'Status', 'trim|required');
$this->form_validation->set_rules('location_city', 'Location City', 'required');
$this->form_validation->set_rules('location_country', 'Location Country', 'required');
if($this->form_validation->run()){
if($query = $this->dashboard_model->update_account()){ //If successful update
$data['message'] = '- update complete...';
}else{
$data['message'] = 'There was an error, update not complete.';
}
}
//echo $name;
$data['account'] = $this->dashboard_model->get_account($account_id,$platform);
$this->load->view('manage/edit',$data);
}
}
Model:
Code:
function update_account(){
$data = array(
'name'=>$this->input->post('name'),
'status' => $this->input->post('status'),
'location_city' => $this->input->post('location_city'),
'location_country' => $this->input->post('location_country')
);
$where = array(
'account_id' => $this->input->post('account_id'),
'platform' => $this->input->post('platform')
);
$update = $this->db->update('db_accounts', $data, $where);
return $update;
}
}
?>
View:
Code:
<?php
$hidden = array(
'account_id' => $faccount_id['value'],
'platform' => $fplatform['value'],
'location_city' => $flocation_city['value'],
'location_country' => $flocation_country['value'],
'status' => $fstatus['value']
);
echo '<form method="post" accept-charset="utf-8">';
echo form_hidden($hidden);
//Platform
echo '<span font-weight:bold"><font color="#C40909">'.$fplatform['value'].'</font>' ;
if(isset($message))
{
echo '<font color=#C40909> '.$message.'</font></span>';
};
//Header Name
echo '<h1 class="header"><span class="title">' .set_value('name', $fname['value']).'</span></h1>';
?>
<table width="700" cellpadding="0" cellspacing="0">
<tr>
<td width="325"><strong>Name </strong>
<input type="text" name="name" value="<?php echo set_value('name', $fname['value']); ?>" size="50"/></td>
<td valign="top" color:#C40909;"> <?php echo form_error('name'); ?></td>
</tr>
<tr>
<td width="325"><strong>Location: City </strong>
<input type="text" name="location_city" value="<?php echo set_value('location_city', $flocation_city['value']); ?>" size="50"/></td>
<td valign="top" color:#C40909;"> <?php echo form_error('location_city'); ?></td>
</tr>
<tr>
<td width="325"><strong>Location: Country </strong>
<input type="text" name="location_country" value="<?php echo set_value('location_country', $flocation_country['value']); ?>" size="50"/></td>
<td valign="top" color:#C40909;"> <?php echo form_error('location_country'); ?></td>
</tr>
<tr>
<td width="325"><strong>Status </strong>
<?php
$status_options = $this->lang->line('status');
echo form_dropdown('status', $status_options, $fstatus['value']);
?></td>
<td valign="top" color:#C40909;">
<?php echo form_error('status'); ?></td>
</tr>
</tr>
</table>
<?php
$data = array('name' => 'submit', 'value' => 'Update Account', 'style' => 'width:313px');
echo form_submit($data);
echo form_close();
?>