【发布时间】:2016-04-30 08:21:35
【问题描述】:
好的,我有未读的报告表和报告表,点击按钮StaffID 和ReportID 会发送已读表(Read_Report)。
我可以检索所有与人员 ID 匹配的已读报告(查询 1)
我可以获得不在两个表中但仅在报告中的所有报告(查询 2)。
但是,在查询 2 中,我需要获取 1 也未读取且 2 与会话 ID 相关的报告。
报告
- 报告 ID (PK)
有什么办法可以让这个工作吗?
Read_Report
- 员工编号 (FK)
- 报告 ID (FK)
报告
工作中 (查询 1)
function get_read_report()
{
$this->db->select('report.Report_Name, report.ReportDate, report.ReportID')
->from('report')
->join('Read_Report', 'report.ReportID = Read_Report.ReportID')
->where('Read_Report.StaffID', $this->session->userdata("StaffID"));
$result = $this->db->get();
return $result->result();// fetch data then return
}
不是用户个人的 (查询 2)。
function get_unread_report()
{
$this->db->select('report.Report_Name, report.ReportDate, report.ReportID')
->from('report')
->join('Read_Report', 'report.ReportID = Read_Report.ReportID', 'left')
->where('Read_Report.ReportID IS NULL');
// ->where('Read_Report.StaffID',$this->session->userdata("StaffID"));
$result = $this->db->get();
return $result->result();
}
【问题讨论】:
标签: php sql codeigniter join