我正在尝试编写具有MAX,SUBSTRING和CAST的CodeIgniter查询,它们返回一个整数值 . 这就是我在传递前缀(AL,PK等)的模块中所拥有的:
function getMaxIDMatchingPrefix($locationPrefix){
$sql = "SELECT MAX( SUBSTRING( locationID , 3, 11 ) )
FROM items WHERE LEFT( locationID , 2 ) = = ? ";
$query = $this->db->query($sql, $locationPrefix);
return $query;
}
这是我在控制器中检索整数值(1或3或114等):
$location_max_id = $this->location_model->getMaxLocationID($locationPrefix);
但是我收到一个错误: Object of class CI_DB_mysql_result could not be converted to string 有人可以帮帮我吗?
1 回答