當我嘗試獲取特定的ID並且不讓我保存表單時,拋出了數組到字符串的轉換。我只需要爲'自動填充字段'而設置'intervaloHorario'的id,但我不知道我做錯了什麼。請給我一個手。PHP迭代查詢結果時,foreach無法正常工作
錯誤
嚴重性: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);
}
我想你可以通過'gettype($ query)'來查看'$ query'變量的類型。 –