Welcome Guest, Not a member yet? Register   Sign In
have to refresh page to get value using drop down list
#1

[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>';
?&gt;
<table width="700" cellpadding="0" cellspacing="0">
<tr>
        <td  width="325"><strong>Name&nbsp; </strong>
      &lt;input type="text" name="name" value="&lt;?php echo set_value('name', $fname['value']); ?&gt;" size="50"/&gt;&lt;/td>
        <td valign="top"  color:#C40909;">&nbsp;  &lt;?php echo form_error('name'); ?&gt;</td>
</tr>
     <tr>
        <td  width="325"><strong>Location: City&nbsp;</strong>
      &lt;input type="text" name="location_city" value="&lt;?php echo set_value('location_city', $flocation_city['value']); ?&gt;" size="50"/&gt;&lt;/td>
        <td valign="top"  color:#C40909;">&nbsp;  &lt;?php echo form_error('location_city'); ?&gt;</td>
</tr>
    
    <tr>
        <td  width="325"><strong>Location: Country&nbsp; </strong>
      &lt;input type="text" name="location_country" value="&lt;?php echo set_value('location_country', $flocation_country['value']); ?&gt;" size="50"/&gt;&lt;/td>
      <td valign="top"  color:#C40909;">&nbsp;  &lt;?php echo form_error('location_country'); ?&gt;</td>
</tr>
    <tr>
        <td width="325"><strong>Status&nbsp; </strong>
        &lt;?php
  $status_options = $this->lang->line('status');  
        echo form_dropdown('status', $status_options, $fstatus['value']);
  ?&gt;</td>
        <td valign="top"  color:#C40909;">&nbsp;  
  &lt;?php echo form_error('status'); ?&gt;</td>
</tr>
</tr>
  
    
</table>
&lt;?php
   $data = array('name' => 'submit', 'value' => 'Update Account', 'style' => 'width:313px');
  echo form_submit($data);
  echo form_close();
?&gt;


#2

[eluser]TheFuzzy0ne[/eluser]
In your view, try:
Code:
echo form_dropdown('status', $status_options, set_value('status', $fstatus['value']));
#3

[eluser]deongee[/eluser]
This worked, thanks so much for your help.




Theme © iAndrew 2016 - Forum software by © MyBB