我想在textarea中显示最后插入的记录,这是我按下提交按钮之后的tinymce编辑器记录应该提交并且 在id的帮助下,应该在模型的帮助下从数据库中获取相同的记录并返回到控制器然后传递 要查看,但我无法将最后插入的记录从模型传递到控制器和视图。请帮助解决我的问题。
控制器:
public function create_user(){
$goal1=$this->input->get_post('description1');
$goal2=$this->input->get_post('description2');
$goal3=$this->input->get_post('description3');
$id=$this->input->post('c_id');
$data=array('goal1'=>$goal1,'goal2'=>$goal2,'goal3'=>$goal3);
$result_goal = $this->course_user->create_user($data,$id);
//Code to retrieve last record
$result_updated_record = $this->course_model->get_last_record($id);
if($result_updated_record!='false')
{
return $result_updated_record;
}
else
{
return false;
}
}
型号:
public function get_last_record($last_id)
{
$condition = "id =" . "'" . $last_id . "'";
$this->load->database();
$this->db->select("*");
$this->db->from("goal");
$this->db->where($condition);
$query=$this->db->get();
$res = $query->result_array();
}
查看:
$.ajax({
type: 'POST',
url: "<?php echo base_url();?>c_user/create_user",
cache: false,
data: dataString,
success: function(data){
tinymce.get('id_description1').setContent('');
tinymce.get('id_description2').setContent('');
tinymce.get('id_description3').setContent('');
},
error: function(){
alert('Error while request...');
}
});
答案 0 :(得分:0)
使用$this->db->insert_id()
将返回最后插入的记录主键。