Jeeva Jeeva - 2 months ago 6
MySQL Question

How to get last inserted row value from a column in string format?

Is there any way to fetch the last inserted value from a column in string format. The following code doesnt work

$studentId=$this->db->get('iproj_stud_course', "i_stud_id");


here the "ipoj_stud_course" is the table and "i_stud_id" is the column.

Answer

use below way

    $this->db->select('i_stud_id');
    $this->db->order_by('i_stud_id','desc');  //i_stud_id is auto_increment
    $this->db->limit(1);
    $query = $this->db->get('iproj_stud_course');
    $studentId=$query->row_array();
    echo $studentId['i_stud_id'];
Comments