Welcome Guest, Not a member yet? Register   Sign In
Selecting the value of a radio/checkbox from a database value.
#1

[eluser]BandonRandon[/eluser]
So I am extreamly new to CI. Also I'm actually using PyroCMS but the set up is the same. I am storing a value of my radio button in my database as a numeric value (1,2,3) I am trying to figure out how to pull that out when I go to edit the entry.

My View File has this
Code:
<li class="&lt;?php echo alternator('', 'even'); ?&gt;">
             <label for="primary_phone">&lt;?php echo lang('employee.primary_phone'); ?&gt;</label>
             &lt;input type="radio" name="primary_phone" value="work_phone" &lt;?php echo set_radio('primary_phone[]', 'work_phone',$this-&gt;employee_m->get_employee_info($id,'primary_phone','work_phone'));?&gt; /> &lt;?php  echo lang('employee.work_phone'); ?&gt;
             &lt;input type="radio" name="primary_phone" value="home_phone" &lt;?php echo set_radio('primary_phone[]', 'home_phone',$this-&gt;employee_m->get_employee_info($id,'primary_phone','home_phone')); ?&gt; /> &lt;?php  echo lang('employee.home_phone'); ?&gt;
             &lt;input type="radio" name="primary_phone" value="cell_phone" &lt;?php echo set_radio('primary_phone[]', 'cell_phone',$this-&gt;employee_m->get_employee_info($id,'primary_phone','cell_phone')); ?&gt; /> &lt;?php echo lang('employee.cell_phone'); ?&gt;
             <p>&lt;?php echo lang('employee.primary_phone_desc'); ?&gt;</p>

            </li>

In my module I have
Code:
public function get_employee_info($id,$info,$field='')
    {            
          if($info == "primary_phone"){
            $employee_info_query = $this->db->select('primary_phone')->from('database')->where('id', $id)->get();
            $primary_phone_numeric= $employee_info_query->row()->primary_phone;
        
            if(($primary_phone_numeric =='1') && ($field='work_phone')){ $employee_info = 'TRUE';}
            elseif(($primary_phone_numeric =='2') && ($field='home_phone')){ $employee_info = 'TRUE';}
            elseif(($primary_phone_numeric =='3') && ($field='cell_phone')){ $employee_info = 'TRUE';}
            else {$employee_info = 'FALSE';}
}
}

The idea is if the field value is the correct name and the number matches the value to make it as true else mark it as false. Right now it seems no value is being passed to the view at all.
#2

[eluser]steelaz[/eluser]
In your model function I don't see any "return" statement, I didn't look carefully at your code, but you probably need to add "return (bool)$employee_info;" at the end of your function.




Theme © iAndrew 2016 - Forum software by © MyBB