简体   繁体   中英

i need to insert employee and service id in a table

I need to insert employee id and service id into a new table addservice.i wrote a function add in my controller page where i get my employee id from the session and service id from the service table from the uri. In controller

public function add()
    {
    $this->load->library('session');

    $id = $this->uri->segment(4);
    $data_to_store = array('employee_id'=>$taxdetails['total'],
    'service_id'=>$id);
    $this->selected_model->store_employee($data_to_store);
                     $data['main_content'] = 'admin/selected/list';
        $this->load->view('includes/template', $data);  

    }

in model: this is my model file where wrote the code to insert the employee id and service id.

public function store_employee($data)
    {
        $insert = $this->db->insert('addservice', $data);
        return $insert;
    }

in view page

<div class="container top">

      <ul class="breadcrumb">
         <li>
          <a href="http://localhost/elfanto/elfanto_billing/admin/addservice">
            Admin          </a> 
          <span class="divider">/</span>
        </li>
        <li class="active">
          Service        </li>
      </ul>


     <div class="row">
        <div class="span12 columns">
          <div >

            <?php

            $attributes = array('class' => 'form-inline reset-margin', 'id' => 'myform');

            $options_manufacture = array(0 => "all");
            foreach ($category as $row)
            {
              $options_manufacture[$row['id']] = $row['name'];
            }
            //save the columns names in a array that we will use as filter         
            $options_products = array();    
            foreach ($service as $array) {
              foreach ($array as $key => $value) {
                $options_products[$key] = $key;
              }
              break;
            }


            ?>

          </div>

          <table class="table table-striped table-bordered table-condensed">
            <thead>
              <tr>
                <th class="header">Service id</th>
                <th class="yellow header headerSortDown">Service name </th>
                <th class="green header">Service catogary</th>
                <th class="red header">Service tax</th>
                <th class="red header">Service length</th>
                <th class="red header">Service price</th>
                <th class="red header">Actions</th>
              </tr>
            </thead>
            <tbody>
              <?php
              foreach($service as $row)
              {
                echo '<tr>';
                echo '<td>'.$row['id'].'</td>';
                echo '<td>'.$row['service_name'].'</td>';
                echo '<td>'.$row['category'].'</td>';
                echo '<td>'.$row['service_tax'].'</td>';
                echo '<td>'.$row['service_length'].'</td>';
                echo '<td>'.$row['service_price'].'</td>';
                echo '<td class="crud-actions">
                  <a href="'.site_url("admin").'/selected/add/'.$row['id'].'" class="btn btn-info">Add service</a>  

                </td>';
                echo '</tr>';
              }
              ?>      
            </tbody>
          </table>
 <a href='admin/employee/add' class="btn btn-info">Continue as chair renter</a> 
          <?php echo '<div class="pagination">'.$this->pagination->create_links().'</div>'; ?>

      </div>
    </div>

this code doesnt work for. i am not able to resolve my problem can someone correct my code.

In your url try adding index.php after projectname http://localhost/elfanto/index.php/elfanto_billing/admin/addservice and the link does not match the functions.

Example

http://localhost/project/index.php/controller/add/

First I would recommend auto load the session library to get

To get any set session userdata you need to do some thing like but do not know how you set your sessions.

$this->session->userdata('total')

Controller Function

public function add() {
    $this->selected_model->store_employee();

    $data['main_content'] = 'admin/selected/list';
    $this->load->view('includes/template', $data);  

}

Model Function

public function store_employee()
{

    $data = array(
        'employee_id' => $this->session->userdata('total'),
        'service_id' => $this->uri->segment(4)
    );

    $this->db->insert('addservice', $data);

}

if session set in array()

$taxdetails = $this->session->userdata('some_array_name');

$taxdetails['total']

Function example 2

public function store_employee()
{

$taxdetails = $this->session->userdata('some_array_name');

    $data = array(
        'employee_id' => $taxdetails['total'],
        'service_id' => $this->uri->segment(4)
    );

    $this->db->insert('addservice', $data);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM