首页 文章

codeigniter查询

提问于
浏览
0

我正在尝试编写具有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 回答

  • 0

    $ query-> result_array()返回一个数组数组,你可以在foreach循环中使用$ sale ['name'] . $ query-> result()返回一个stdclass对象数组,你可以在foreach循环中使用$ sale-> name .

相关问题