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

标签 php mysql codeigniter codeigniter-2

我想在我按下提交按钮后在 tinymce 编辑器中显示最后插入的记录,记录应该被提交并且 在id的帮助下,应该在模型的帮助下从数据库中获取相同的记录并返回给 Controller 然后传递 继续查看,但我无法将最后插入的记录从模型传递到 Controller 和 View 。请帮助解决我的问题。

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() 将返回最后插入的记录主键。

关于php - 使用 Codeigniter 在文本框中显示最后插入的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34563094/

相关文章:

javascript - 需要 Auth0 RememberLastLogin 参数信息来获取普通链接选项

java - 如何让任意IP地址连接到远程MySQL服务器?

mysql - 在 Windows 7 上重新启动 mysql 服务器

mysql - 将 varchar 列中的十六进制数字转换为无符号整数?

php - Codeigniter 从数据库记录中选择前一天

java - 重力形式签名 - 从 PHP 到 java

php - Symfony Composer 安装而不清除缓存

php - createQueryBuilder/加入列 - Symfony

php/Codeigniter--如何通过排除时间来比较日期

php - 带有数据库选择的 CodeIgniter :