我正在尝试更新输入行的 id 并通过下拉列表选择标题的表,但我有两个问题。首先我不确定如何将数据传递给模型,第二个问题实际上是使用活动记录更新表。
控制器类
class Update extends CI_Controller {
public function __construct()
{
parent::__construct();
//$this->load->model('addmodel');
//$this->load->helper('form');
}
public function index()
{
$this->load->view('updview');
}
public function updtitle()
{
$data = array(
'id' => $this->input->post('id'),
'title' => $this->input->post('title') );
//$data1['data'] = $data;
$data1['data'] = $this->updmodel->upddata($data);
$this->load->view('updview', $data1);
}
}
?>
模型类
class Updmodel extends CI_Model {
// model constructor function
function __construct() {
parent::__construct(); // call parent constructor
$this->load->database();
}
public function upddata($data) {
$this->db->where('emp_no', $data['id']);
$this->db->update('title', $data['title']);
return;
}
}
?>
看法
更新员工头衔
<form action="http://localhost/ecwm604/index.php/update/updtitle" method="POST">
employee id:
<input type=text name="id"><br />
change title to:
<select name="title">
<option value="Assistant Engineer">Assistant Engineer</option>
<option value="Engineer">Engineer</option>
<option value="Senior Engineer">Senior Engineer</option>
<option value="Senior Staff">Senior Staff</option>
<option value="Staff">Staff</option>
</select><br />
<input type="submit" value="submit"/>
<br />
<?php
print_r($data);
//echo $data['title'];
?>
</body>
</html>