Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14114

How to batch insert multiple rows with different data

$
0
0
Hello!  Can someone help me out?  I'm trying to batch insert into my sponsors table.  I have visited multiple help sites, but none of their solutions seem to work on mine.  I'm trying to input the following:

sponsor_id - PK (AUTO_INCREMENT)
firstname
middlename
lastname
baptism_id - FK 

Here's my code for the VIEW
PHP Code:
<div class="tab-pane" id="tab5">
 
   <section id="sponsor-field">
 
       <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 ">
 
           <br>
 
           <div class="col-lg-6">
 
               <label for="number of sponsors">Select the number of your sponsor/s:</label>
 
           </div>
 
           <div class="col-lg-3">
 
               <select id="txtboxnum" name="txtboxnum" class="form-control input-sm col-sm-4 col-md-4 col-lg-4" required>
 
                   <option value="1">1</option>
 
                   <option value="2">2</option>
 
                   <option value="3">3</option>
 
                   <option value="4">4</option>
 
                   <option value="5">5</option>
 
                   <option value="6">6</option>
 
               </select>
 
           </div>
 
           <br/>
 
           <hr>
 
           <div id="txtboxgen" class="form-group">
 
           </div>

 
       </div>
 
   </section>
</
div

Oh yeah, also, my textboxes are generated based on the number selected by the user.  It is done by Javascript.  Here's the code for that as well.

Code for TEXTBOX GENERATION via Javascript
PHP Code:
$("#txtboxnum").change(function(e) {
 
           'use strict';
 
           create($(this).val());
 
       });

 
       function create(param) {
 
           'use strict';
 
           var i;
 
           $("#txtboxgen").empty();
 
           for (0param+= 1) {

 
               $('#txtboxgen').append('<label for="Sponsor#' '">Sponsor #  ' '</label><input type="text" class="form-control input-sm" name="sponsor[' ']["firstname"]" required placeholder="First Name"><br/><input type="text" class="form-control input-sm" name="sponsor[' ']["middlename"]" placeholder="Middle Name"><br/><input type="text" class="form-control input-sm" name="sponsor[' ']["lastname"]" required placeholder="Last Name"><br/>');

 
           }
 
       

Here's my code for the CONTROLLER
PHP Code:
$size $this->input->post('txtboxnum');
 
           $data $this->input->post('sponsor');
 
                       
            $sponsors_query 
$this->baptism_model->insert_sponsors($data);
 
           
            if
($sponsors_query){
//                echo '<script>alert("Successfully added reservation!");</script>';
//                redirect('./home-page/Main/servicerequest');
 
               echo 'YES';
 
           }else{
//                echo '<script>alert("There appears to be something wrong.");</script>';
 
               echo 'NO';
 
           

Here's for my MODEL
PHP Code:
   function insert_sponsors($sponsors){
 
       
        $query 
$this->db->insert_batch('tbldummy'$sponsors);                
        if
($query){
 
            return true;
 
       }else{
 
           return false;
 
       }
 
      
    



Any help is very much appreciated!  Thank you!  Smile

Viewing all articles
Browse latest Browse all 14114


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>