Beep Beep - 7 months ago 7
SQL Question

Retrieve data only linked to that session

I need to get data where

UserID_Staff
matched the session
StaffID


My query

$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();


Any Idea why i get this error, and how to change my query ?

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

Answer
$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();

you miss ',' near Report_Comments.Comment_Date , staff.Staff_Username

Comments