Jump to content

php codeignator


sanem

Recommended Posts

data store in db as same as table using party_id

 

view :-

<form action="<?php echo base_url(); ?>daily_orders/do_add" id="frmvalidate" method="post" role="form" enctype="multipart/form-data">
          <div class="box-header">
            <div class="row">
              <div class="col-lg-2">
                <input type="date" name="order_date" class="form-control" value="<?php echo date('Y-m-d'); ?>">
              </div>
           </div>
          </div>

          <div class="box-body table-responsive">

                <table class="table table-bordered table-condensed table-hover table-striped" id="dtHorizontalExample" width="1200px;">
                  <thead>
                    <tr>
                      <th style="color: #d81b60;"> Party Name \ Product Name</th>
                                
                        <?php foreach ($products as $key => $value) {?>
                        <th> 
                          <input type="text" name="product_name[]" class="form-control" value="<?php echo $value['product_name'].' - '.$value['quantity'].' '.$value['unit_measurmrnt']; ?>" readonly>
                        </th>
                        <?php } ?>

                    </tr>
                  </thead>
                  <tbody>
                   
                        <tr>
                            <?php foreach ($party_master as $key => $value) {?>
                          <tr>
                            <th>
                               <input type="text" name="party_name[]" class="form-control" value="<?php echo $value['party_name']; ?>" readonly>

                               <input type="hidden" name="party_id[]" value="<?php echo $value['id']; ?>">


                        <?php foreach ($products as $key => $value1) { ?> 
                            <th><input type="text" name="quantity_<?php echo $value['id'] ?>_<?php echo $value1['id'] ?>" class="form-control" placeholder="quantity"></th>

                            <input type="hidden" name="product_name_<?php echo $value['id'] ?>_<?php echo $value1['id'] ?>" value="<?php echo $value1['id']; ?>">
                        <?php } ?>

                          </tr>
                            <?php } ?>
                         
                        </tr>
                  
                  </tbody>
                </table>

                <div class="box-footer">
                  <button type="submit" class="btn bg-maroon btn-flat pull-right">Submit</button>
                </div>
          </div>
</form>
 

controller :- 
    function do_add()
    {
      $cng=count($_POST['party_id']);
     for ($i=0; $i < $cng; $i++) { 

        $cng1=count($_POST['product_name_'.$_POST['party_id'][$i]]);
        for ($m=0; $m < $cng1; $m++) { 
            $insert_arr = array(
            'party_id'=>$_POST['party_id'][$i],
            'order_date'=>$_POST['order_date'],
            'party_name'=>'',
            'product_name'=>'',
            'quantity'=>$_POST['quantity_'.$_POST['party_id'][$i]]
          );

            print_r($insert_arr);die();
    
          $this->modeladmin->insertdata("daily_orders",$insert_arr);
       }

        }
    
          redirect(base_url().'daily_orders');
    }

modeladmin :- 

    function insertdata($tablename, $postdata){
        $created_by = $this->session->userdata('admin_data');
        $created_on = date('Y-m-d H:i:s');

        $postdata['created_by'] = $created_by;
        $postdata['created_on'] = $created_on;

        if($this->db->insert($tablename, $postdata))
        {
            return true;
        }else{
            return false;
        }
    }

code.PNG

Link to comment
Share on other sites

Things you'll need to do to get help:

  1. Describe what the code should be doing
  2. Describe what the code is doing instead
  3. Show us any errors you're getting in your browser
  4. Show your relevant code
  5. If it seems like the error could be a database problem, describe the data and its structure
  6. Explain what you've done so far to fix the issue(s)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.