【问题标题】:i need to insert employee and service id in a table我需要在表中插入员工和服务 ID
【发布时间】:2015-06-29 10:02:12
【问题描述】:

我需要将员工 id 和服务 id 插入新表 addservice。我在控制器页面中编写了一个函数 add,我从会话中获取员工 id,从 uri 中的服务表中获取服务 id。 在控制器中

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);  

    }

在模型中: 这是我的模型文件,其中编写了插入员工 ID 和服务 ID 的代码。

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

在查看页面中

<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>

此代码不起作用。我无法解决我的问题,谁能更正我的代码。

【问题讨论】:

  • 不起作用是什么意思?
  • 我没有收到任何错误我得到一个白页
  • 在您的控制器中,$taxdetails 是什么?
  • 这是一个会话变量,我在另一个控制器 employee_controller 中拥有
  • 所以当你点击“添加服务”按钮时,你只是得到一个白屏,没有插入数据?

标签: php mysql codeigniter


【解决方案1】:

在你的 url 中尝试在 projectname http://localhost/elfanto/index.php/elfanto_billing/admin/addservice 之后添加 index.php 并且链接与函数不匹配。

示例

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

首先我会推荐自动加载会话库来获取

要获取任何设置的会话用户数据,您需要执行一些操作,例如但不知道如何设置会话。

$this-&gt;session-&gt;userdata('total')

控制器功能

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

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

}

模型函数

public function store_employee()
{

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

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

}

如果在 array() 中设置会话

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

$taxdetails['total']

函数示例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);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多