• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dropdown with CI

#1
[eluser]umefarooq[/eluser]
Hi
i want to create dropdown with CI im sending data to my view from controller
Code:
$data['width'] = array('name' => 'width','id' => 'width');
$data['height'] = array('name' => 'height','id' => 'height');
$data['scalecontent'] = array('name' => 'scalecontent','id' => 'scalecontent');

First to are text box but how can i send options for the third scalecontent along with data parameters.

#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

#3
[eluser]umefarooq[/eluser]
hi really thanks for reply and its work very fine. but another problem im facing is that where dropdown is created on viewing source in name attribute of dropdown it show Array, not he name which im sending trough data here is the data which im sending for dropdown

$data['scalecontent'] = array('name' => 'scalecontent','id' => 'scalecontent');

#4
[eluser]hvalente13[/eluser]
It's all about this line here:

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

You have to specify $scalecontent['name'], because you have instantiated the array in your controller. That shouldn't give you Array, but the value for the 'name' key of your array scalecontent.

Check it out... I'll try to run it if there's any bug, but at first glance I don't think so


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.