Guest User

foreach problem

a guest
Jun 11th, 2012
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //i am using codeigniter
  2.  
  3. //my view file is
  4.  
  5. <p class="scent">
  6.         <label for="test">Test </label>
  7.         <?php echo form_dropdown('test[]', $dropdown, set_value('test[]'))?>        
  8.         <a href="" class="addScnt">Add</a>
  9.         <a href="" class="remScnt">Remove</a>
  10.         <?php echo form_error('test'); ?><span class="required"></span>
  11. </p>  
  12.  
  13. //controller
  14.  
  15.  
  16.         if ($this->form_validation->run() == FALSE) // validation hasn't been passed
  17.         {
  18.             $this->load->view('admission',$data);
  19.         }
  20.         else // passed validation proceed to post success logic
  21.         {
  22.             // build array for the model
  23.            
  24.             $form_data = array(
  25.                             'pname' => set_value('pname'),
  26.                             'pid' => set_value('pid'),
  27.                             'age' => set_value('age'),
  28.                             'gender' => set_value('gender'),
  29.                             'refdby' => set_value('refdby'),
  30.                             'client' => set_value('client'),
  31.                             'test[]' => set_value('test[]')
  32.                         );
  33.                    
  34.             //run insert model to write data to db
  35.             foreach ($this->input->post('test') as $test) {
  36.  
  37.              //$test_value=$test;
  38.              $pname= $this->input->post('pname');
  39.              $pid= $this->input->post('pid');
  40.              $age= $this->input->post('age');
  41.              $gender=$this->input->post('gender');
  42.              $refdby=$this->input->post('refdby');
  43.              $client=$this->input->post('client');
  44.            
  45.              $this->myform_model->insert_data($pname,$pid,$age,$gender,$refdby,$client,$test);
  46.  
  47.              } 
  48.     }
  49. //model
  50.  
  51.   public function insert_data($pname,$pid,$age,$gender,$refdby,$client,$test){
  52.  
  53.         $query="INSERT INTO patient (pname,pid,age,gender,refdby,client,test) VALUES (?,?,?,?,?,?,?)";
  54.         $this->db->query($query,array($pname,$pid,$age,$gender,$refdby,$client,$test));
  55.  
  56.         redirect('welcome');
  57.       }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×