Welcome Guest, Not a member yet? Register   Sign In
dropdown with CI
#2

[eluser]hvalente13[/eluser]
Hi,

That's how I do it:

Model

Code:
function get_list(){
   $this->db->select('*')->from('table');
   $query = $this->db->get();

   if($query->num_rows()>0){
      $opts[''] = 'Select an option';
      foreach($query->result() as $row){
          $opts[$row->id] = $row->name;
      }
   }

   return $opts;
}

Controler

Code:
// with this option you can compare with the db data, and i will select the right option when page loads
// model function to retrieve db data

$data['name'] = $row->name;


$data['dd_data'] = $this->model_name->get_list();


View
Code:
<?php echo form_dropdown('name',$dd_data,$name); ?>

EDIT:

You can pass parameters by:

Code:
<?php echo form_dropdown(array('name'=>$scalecontent['name'],'id'=>$scalecontent['id']),$dd_data,$name); ?>

Guess I didn't forget anything. I was trying to make it generic...

Hope this helps
Hvalente13


Messages In This Thread
dropdown with CI - by El Forum - 10-13-2008, 07:23 AM
dropdown with CI - by El Forum - 10-13-2008, 08:48 AM
dropdown with CI - by El Forum - 10-14-2008, 04:13 AM
dropdown with CI - by El Forum - 10-14-2008, 05:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB