简体   繁体   English

使用Codeigniter在文本框中显示最后插入的记录

[英]Show last inserted record in Textbox using Codeigniter

I want to show last inserted record in textarea which is tinymce editor after I press submit button the record should get submitted and with the help of id the same record should be fetched from database with the help of model and returned to controller and then passed on to view, but I'm unable to pass the last inserted record from model to controller and view. 我想在textarea中显示最后插入的记录,这是tinymce编辑器,当我按下Submit按钮后,记录应该被提交,并在id的帮助下,应该使用model的帮助从数据库中提取相同的记录,并返回给控制器,然后继续传递进行查看,但是我无法将最后插入的记录从模型传递到控制器和视图。 Please help to sort out my issue. 请帮助解决我的问题。

Controller: 控制器:

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

}

Model: 模型:

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

View: 视图:

$.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...');
    }
 });

使用$this->db->insert_id()将返回最后插入的记录主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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