gpt4 book ai didi

php - 我需要在表中插入员工和服务 ID

转载 作者:行者123 更新时间:2023-11-29 22:17:14 25 4
gpt4 key购买 nike

我需要将员工 ID 和服务 ID 插入到新表 addservice 中。我在 Controller 页面中编写了一个函数 add,在其中我从 session 中获取员工 ID,并从 URI 的服务表中获取服务 ID。在 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);

}

在模型中:这是我的模型文件,其中编写了插入员工 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>

此代码不起作用。我无法解决我的问题,有人可以更正我的代码吗?

最佳答案

在您的网址中尝试在项目名称 http://localhost/elfanto/index.php/elfanto_billing/admin/addservice 之后添加 index.php并且链接与功能不匹配。

示例

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

首先,我建议自动加载 session 库以获取

要获取任何设置的 session 用户数据,您需要执行类似的操作,但不知道如何设置 session 。

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

Controller 功能

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() 中设置了 session

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

}

关于php - 我需要在表中插入员工和服务 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31112794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com