Welcome Guest, Not a member yet? Register   Sign In
dropdown menu from database
#1

[eluser]the_unforgiven[/eluser]
Hi all,

I want to get some data from a table in my database and post it to a drop down menu, then when the form is submitted post the data to the database updating the client id.

The table for where the client name will come from is tblClientlist (see image)
then that id from client list needs to be stored in the table "meetings" and update that table with the relevent ID from tblClientlist (again see both images)

meetins as the column notes in it and client list has fullname first name etc in it

Controller
Code:
function createmeeting()
{
  // Check if user is logged in
  if ($this->session->userdata('username')) {
  // Load Helper File
  $this->load->helper(array('form', 'url'));
  $this->load->library('form_validation');
  $this->load->model('meeting_model');
  
  // Form Validation
  $this->form_validation->set_rules('notes', 'notes', 'trim|required');
  
  // If validation is FALSE then return back to form
  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('createmeeting');
  }
  
  else
  {
   $q = $this->meeting_model->clientlist($data);
  
   // Load User Model then do Function insert into DB
   $this->meeting_model->add_meeting($data, $q);
  
  }
  }
  else { echo '[removed]
      alert("Sorry you MUST be logged in to view this page, please login!");
      location = "../users";
  [removed]'; }
}

Model
Code:
function add_meeting()
{
  $data = array(
       'date'=>$this->input->post('date'),
    'notes'=>$this->input->post('notes')
  );
  $this->db->insert('meetings', $data);
  $d['title'] = "Create Meeting";
  $d['success'] = $this->session->set_flashdata('success', 'The meeting has been successfully deleted');
  
  $this->load->view('success', $d);
}

View File
Code:
<div id="content">
    &lt;?php
     $attributes = array('class' => 'email', 'id' => 'loginform');
     echo form_open('admin/createmeeting', $attributes);
    ?&gt;
    &lt;?php echo form_hidden('id', $this->uri->segment(3));?&gt;
  
    
    <table>
     <tr><td>Date:</td><td>&lt;?php echo form_input('date'); ?&gt;</td><td>&lt;?php echo form_error('date'); ?&gt;</td></tr>
     <tr><td>Client:</td><td>&lt;?php echo form_dropdown(); ?&gt;</td></tr> // Drop down from DB
     <tr><td>Notes:</td><td>&lt;?php echo form_textarea('notes'); ?&gt;</td><td>&lt;?php echo form_error('notes'); ?&gt;</td></tr>
    </table>
  
    &lt;?php echo form_submit('submit', 'Create New Meeting'); ?&gt;

    &lt;?php echo form_close();?&gt;


  </div>
Help, code examples for very much appreciated.
Thanks in advance Smile




Theme © iAndrew 2016 - Forum software by © MyBB