检索仅链接到该会话的数据

时间:2016-04-29 00:12:21

标签: sql codeigniter session-variables where

我需要获取UserID_Staff与会话StaffID匹配的数据

我的查询

$this->db->select('Report_Comments.Comments, Report_Comments.Comment_Date staff.Staff_Username')
                ->from('Report_Comments')
                ->join('staff', 'Report_Comments.UserID_Staff = staff.StaffID')
                ->where('UserID_Staff', $this->session->userdata("StaffID"));
            return $result = $this->db->get();

任何想法为什么我会收到此错误,以及如何更改我的查询?

 Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.`Staff_Username` FROM `Report_Comments` JOIN `staff` ON `Report_Comments`.`User' at line 1

SELECT `Report_Comments`.`Comments`, `Report_Comments`.`Comment_Date` `staff`.`Staff_Username` FROM `Report_Comments` JOIN `staff` ON `Report_Comments`.`UserID_Staff` = `staff`.`StaffID` WHERE `UserID_Staff` = '3'

Filename: models/report/Report_model.php

Line Number: 115

1 个答案:

答案 0 :(得分:0)

$this->db->select('Report_Comments.Comments, Report_Comments.Comment_Date ,staff.Staff_Username')
                ->from('Report_Comments')
                ->join('staff', 'Report_Comments.UserID_Staff = staff.StaffID')
                ->where('UserID_Staff', $this->session->userdata("StaffID"));
            return $result = $this->db->get();

你想念','靠近Report_Comments.Comment_Date staff.Staff_Username