0

I have two tables: 1. STUDENT- fields are- (studentid,studentname,batch) 2. BATCH- fields are- (batchid,batchname)

I want to populate a dropdown list from the field "batchname" ( from the table "BATCH") and have the batchname selected based on the field-"batch" (from the table "Student")

My controller -

function update($id){
$this->load->model('mod_studentprofile');
$data['query']= $this->mod_studentprofile->student_get($id); //to retrieve information from the table "STUDENT" 
$data['query']= $this->mod_studentprofile->batch_get();

$data['main_content']='update_studentprofile';
$this->load->view('includes/template',$data);
}

My model -

 function batch_get()
{
  $query = $this->db->get('batch');
  return $query->result();

}    

Now, I cannot figure out how to populate the dropdown in the "View". Would you please kindly help me with this?

Thanks in Advance.

2

1 Answer 1

2

You need to put the options you want displayed in the drop down into an array, like so

$options = array(
  'red'   => 'Red',
  'green' => 'Green',
  'blue'  => 'Blue',
);

// The params here are:
// 'color'    => name of the drop down
// '$options' => options for the drop down
// 'red'      => the selected value of the drop down
echo form_dropdown('color', $options, 'red');

What I would do is create a function in my model, say $model->dropdown_options() and use that to get the rows from the database and put them into an array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.