Aug*_*gus 5 php mysql codeigniter
我试图从表中获取codeigniter的最大值,但它不起作用.这是我得到的错误:
严重程度:4096
消息:类CI_DB_mysql_result的对象无法转换为字符串
文件名:database/DB_active_rec.php
行号:427
这是我的功能:
public function getPeriodeNummer($bedrijf_id) {
$this->db->select_max('id');
$this->db->where('bedrijf_id', $bedrijf_id);
$result = $this->db->get('rapporten');
$this->db->select('periode_nummer');
$this->db->where('rapporten_id', $result);
$query = $this->db->get('statistieken_onderhoud');
$data = $query + 1;
return $data;
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是如下:
idwhere bedrijf_id= $bedrijf_idfrom rapporten.periode_nummerfrom = statistieken_onderhoudwhere rapporten_id= id我从步骤1获得的最高值.periode_nummer我从步骤2得到的return那个号码.在此感谢您的帮助!
ste*_*nja 15
尝试
public function getPeriodeNummer($bedrijf_id) {
$this->db->select_max('id');
$this->db->where('bedrijf_id', $bedrijf_id);
$res1 = $this->db->get('rapporten');
if ($res1->num_rows() > 0)
{
$res2 = $res1->result_array();
$result = $res2[0]['id'];
$this->db->select('periode_nummer');
$this->db->where('rapporten_id', $result);
$query = $this->db->get('statistieken_onderhoud');
if ($query->num_rows() > 0)
{
$row = $query->result_array();
$data['query'] = 1 + $row[0]['periode_nummer'];
}
return $data['query'];
}
return NULL;
}
Run Code Online (Sandbox Code Playgroud)