Welcome Guest, Not a member yet? Register   Sign In
dropdown shows index number of array with values issue?
#1

[eluser]Xeroxeen[/eluser]
Hi i'm getting the values from the database and pass it to an array.then pass it to view via controller to show the values.it shows well.but it shows array values along array values index number.why is that?
#2

[eluser]JoostV[/eluser]
Make sure the array you are feeding to the dropdown is a key => value pair array.

Code:
$options = array(
    '' => 'Pick a color',
    'white' => 'White',
    'purple' => 'Purple',
    'yellow' => 'Yellow',
);
echo form_dropdown('shirts', $options);
#3

[eluser]Xeroxeen[/eluser]
[quote author="JoostV" date="1373866307"]Make sure the array you are feeding to the dropdown is a key => value pair array.

Code:
$options = array(
    '' => 'Pick a color',
    'white' => 'White',
    'purple' => 'Purple',
    'yellow' => 'Yellow',
);
echo form_dropdown('shirts', $options);
[/quote]

thanks for your comment.this is my model,controller and view parts

model

Code:
function getDBdata()
{
  $dataGet="SELECT Name FROM `data`";
  $dataGetQuery=$this->db->query($dataGet);
  $result=$dataGetQuery->result_array();
  
  foreach ($result as $values){
   $elements[]=$values;
  }
  return $elements;
}

controller

Code:
$elements=$this->dataModel->getDBdata();
  
  
  $data['datagot']=$elements;
  
  $this->load->view('user',$data);

view

Code:
<div class="LeftSide">&lt;?php echo 'Category';?&gt;</div>
    <div class="RightSide">&lt;?php echo form_dropdown('selectedvalue', $datagot, 'Datadropdown');?&gt;</div>

Data in dropdown shows well.but it shows with array index number.
Ex:-

0 data1
1 data1
2 data3 like that.I want only data1,data2,data3.Hope u can help me Smile
#4

[eluser]JoostV[/eluser]
In your model, do:
Code:
foreach ($result as $values){
   $elements[$values['Name']]=$values['Name'];
}
#5

[eluser]Xeroxeen[/eluser]
Thanks it's working properly now Smile





Theme © iAndrew 2016 - Forum software by © MyBB