I am trying to populate a dropdown from a database. In my view file I have the following code
$batch= $query ['batch']; // I pull this data from a separate model echo form_dropdown('shirts', $options, $batch);
Now the drop-down list fills the data, but the problem is that I do not get the value - "$ batch" is automatically selected when the page loads. Interestingly, if I drive away $ batch, the correct data is displayed elsewhere on the page, which means that $ batch is fine.
Here is my controller
function update($id){ $this->load->model('mod_studentprofile'); $data['query']= $this->mod_studentprofile->student_get($id); $data['options']= $this->mod_studentprofile->batchget(); $data['tab'] = "Update Student Information"; $data['main_content']='update_studentprofile'; $this->load->view('includes/template',$data); }
And here is my model
function batchget() { $this->db->select('batchname'); $records=$this->db->get('batch'); $data=array(); foreach ($records->result() as $row) { $data[$row->batchname] = $row->batchname; } return ($data); }
Could you help me solve this problem. I want the value of "$ batch" to be automatically selected from the drop-down list when the page loads.
Thanks at Advance.
EDit ... my model for student_get ($ id)
function student_get($id) { $query=$this->db->get_where('student',array('studentid'=>$id)); return $query->row_array(); }
Thanks:)
source share