Welcome Guest, Not a member yet? Register   Sign In
form_dropdown issues

I'm having issues figuring out how to dynamically set the selected value on my drop down box. Does anyone know of a good tutorial for using drop down boxes?

It is all in the user guide:


"The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected."

So just set as third param, dymically what you want to be pre-selected.


I've looked over the user guide and these forums several times. I'm sure it's something simple and I'm over looking it. I'm using drop down box to edit the position an item shows up in a menu. I want the current position the item is to be the selected value. Here's what I currently have in my code.

# This will return an array with each page position.
function page_position_count($subject_id) {
  $page_set = $this->db->from('pages')->where('subject_id', $subject_id)->get();

  if($page_set->num_rows() > 0) {
   foreach ($page_set->result() as $page) {
    $data[$page->id] = $page->position;
   return $data;

<p> Position: &lt;?php echo form_dropdown('position', $page_count, /* Mystical 3rd param */); ?&gt; </p>

function edit_page($sel_subject = NULL, $sel_page = NULL) {
  $header_data['title'] = 'Widget Corp: Edit Page';
  $data['subjects'] = $this->get_func_model->get_all_subjects();
  $data['pages'] = $this->get_func_model->get_pages_for_subject($sel_subject, false);
  $data['private_nav'] = $this->nav_model->private_navigation($sel_subject);
  $data['cur_page'] = $this->get_func_model->get_page_by_id($sel_page);
  $data['cur_subject'] = $this->uri->segment(3);

  //Passes the array of positions to the view
  $data['page_count'] = $this->get_func_model->page_position_count($sel_subject);
  $this->load->view('includes/header', $header_data);
  $this->load->view('edit_page_view', $data);


I figured it out. I used
as the third param. which is the page id and is used for the array key. I thought I already tried this, but I guess I just thought about doing it and for some reason thought it wouldn't work. I guess I just needed to step away from the computer for a bit. Tongue

Thanks for your reply Smilie.

Theme © iAndrew 2016 - Forum software by © MyBB