Saving data from a drop down list in CodeIgniter -


i created menu page has drop down menu list of menus database , has textbox enter new menus.

the problem i'm having can't seem figure out how save dropdown. example have menu called "about us" in drop down list , want create new menu called "team", , "team" child of "about us"

so in table have this

 id | parent | title ------------------------  1  | null   |  2  | 1      | team 

menu controller

function get_data_from_post() {     $data['title'] = $this->input->post('title', true);     $data['parent'] = $this->input->post('parent', true);       if(!isset($data)){         $data = '';     }      return $data; }  function get_data_from_db($update_id) {     $query = $this->get_where($update_id);      foreach($query->result() $row){         $data['title'] = $row->title;         $data['parent'] = $row->parent;     }      return $data; }  function create() {     $update_id = $this->uri->segment(3);     $submit = $this->input->post('submit', true);      if($submit == "submit"){         //person has submitted form         $data = $this->get_data_from_post();     }else{         if(is_numeric($update_id)){             $data = $this->get_data_from_db($update_id);         }     }      if(!isset($data)){         $data = $this->get_data_from_post();     }       //$titles = array();      $query = $this->get('title');     foreach($query->result() $row){         $titles[] = $row->title;     }      $data['titles'] = $titles;      $data['update_id'] = $update_id;      $data['view_file'] = "create";     $this->load->module('templates');     $this->templates->admin_template($data); }  function submit() {     $this->load->library('form_validation');      $this->form_validation->set_rules('title', 'title', 'required|xss_clean');      if($this->form_validation->run($this) == false){         $this->create();     }else{         $data = $this->get_data_from_post();            $update_id = $this->uri->segment(3);          if(is_numeric($update_id)){             $this->_update($update_id, $data);         }else{             $this->_insert($data);         }          redirect('menus/manage');     } } 

create.php view

<div class="row"> <div class="col-md-12">     <h2>create menus</h2>        <h5>welcome jhon deo , need make dynamic. </h5> </div> </div>  <hr />  <?php     echo validation_errors("<p style='color: red;'>", "</p>");     echo form_open('menus/submit/'.$update_id); ?> <div class="row">     <div class="col-md-12">         <form role="form">         <div class="form-group">     <select name="menus">         <?php             foreach($titles $title){                  echo "<option value=".$title.">".$title."</option>";             }         ?>         </select>       </div>          <div class="form-group">             <label>title</label>             <!-- <input class="form-control" /> -->             <?php                 $data = array(                             'name' => 'title',                             'id' => 'title',                             'value' => $title,                             'class' => 'form-control',                         );                  echo form_input($data);             ?>         </div>          <?php              $data = array(                 'name' => 'submit',                 'id' => 'submit',                 'value' => 'submit',                 'class' => 'btn btn-success',                 'style' => 'width: 100%',             );              echo form_submit($data);         ?>     </form> </div> </div>  <?php         echo form_close(); ?> 

update: have when print_r($titles)

array (     [0] =>     [1] => home ) 

if there don't understand or if need me give more information please let me know.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

delphi - Indy UDP Read Contents of Adata -