我想获取tbl_systemstatus.systemid值作为变量,以便在相同的where子句中使用。 现在任何人都可以给我解决方案,如何创建 tbl_systemstatus.systemid 变量以在同一查询中用于搜索数据。
$this->db->select('*');
$this->db->from('tbl_systemstatus');
$this->db->join('newsystem as system', 'system.ID = tbl_systemstatus.systemid as $id');
$this->db->where(array('systemid' => $id,'status' => 'CISO approved'));
$this->db->order_by('tbl_systemstatus.id', 'DESC');
$this->db->limit(1);
$query = $this->db->get();
if ($query->num_rows()>0)
{
return $query->result();
}
else
{
return false;
}
使用连接表,您不需要获取 systemid,只需:
function YOUR_FUNCTION_NAME(){
$get = $this->db->query("SELECT s.*,
n.*,
FROM tbl_systemstatus s
INNER JOIN newsystem n ON n.systemID = s.id
WHERE s.status = 'CISO Approved'
ORDER BY s.id DESC LIMIT 1
");
$data = $get->result();
return $data;
}