当我尝试获取特定ID并且不让我保存表单时,抛出数组到字符串转换。我只需要' intervaloHorario'为了自动填充字段,但我不知道我做错了什么。请帮我一把。
错误
严重程度:4096
消息:类stdClass的对象无法转换为字符串
模型功能
public function get_idintervalo($idCitas) {
$query = $this->db->query('SELECT intervaloshorarios.idIntervaloHorario FROM intervaloshorarios INNER JOIN citas '
. 'ON intervaloshorarios.idIntervaloHorario = citas.idIntervaloHorario '
. 'WHERE citas.idCitas = ' . $idCitas . ';');
return $query->result();
}
控制器
$query = $this->Intervalos_Model->get_idintervalo($idCitas);
if ($crud->getState() == "add") {
//It's wroking fine getting this
$crud->change_field_type('idCitas', 'hidden', $idCitas);
foreach ($query as $key) {
//Is not working fine (throws array to string conversion)
$crud->change_field_type('idIntervaloHorario', 'hidden', $key);
}
答案 0 :(得分:1)
假设您正在使用CodeIgnitor Framework。你应该写
foreach ($query as $key) {
//Is not working fine (throws array to string conversion)
$crud->change_field_type('idIntervaloHorario', 'hidden', $key->idIntervaloHorario);
}
因为$ query将查询结果集存储在对象中,而$ key是一个对象。 有关详细信息,请参阅手册https://www.codeigniter.com/userguide2/database/results.html
答案 1 :(得分:0)
这是OpenCart吗? 如果是这样,请使用:
return $query->rows;
获取返回行的数组。