首页 > 解决方案 > 如何将其转换为单个字符串值

问题描述

Array ( [0] => Array ( [Max(Exam_Id)] => 6 ) ) 

public function get_max_exam_id()

{

 $query = $this->db->query("SELECT Max(Exam_Id) from exam_tb");
    return $query->result_array();

}         

标签: mysqlcodeigniter

解决方案


首先你需要添加别名

$query = $this->db->query("SELECT Max(Exam_Id) as max_exam_id from exam_tb");

尝试使用 row_array() 而不是 result_array()

//return $query->result_array();
$result = $query->row_array();
return $result['max_exam_id'];

并使用别名 $result['max_exam_id'] 访问它。也许可以帮助:)


推荐阅读